The decimal fraction of the values in the chart corresponding to the y-axis is not regular.
ex) 1.4200, 1.32, 1.2200 ...
This is a formatter that applies logic that cuts the decimal point. We checked that the input and output values are output normally.
However, the priceFormat function within the addCandlestickSeries indicates an irregular decimal length.
// LWchart.tsx
<Chart
options={options}
candlestickSeries={[{ data: chart }]}
autoWidth
height={380}
onCrosshairMove={(param) => handleCrosshairMoved(param, chart[chart.length - 1])}
chartRef={(chart) => {
chart.timeScale().fitContent();
// chart.timeScale().scrollToPosition(2, true);
chart.addCandlestickSeries({
priceFormat: {
type: "custom",
formatter: (priceValue) => {
return decimalSplit(priceValue);
},
minMove: 0.0000000001,
},
});
}}
/>
// decimalSplit.ts
export const decimalSplit = (value: string | number) => {
// return value;
if (!value) return "0";
const splitStr = String(value).split(".");
if (!splitStr[1]) return splitStr[0];
if (Number(splitStr[0]) > 10) {
return `${splitStr[0]}.${splitStr[1].slice(0, 2)}`;
} else if (Number(splitStr[0]) > 0) {
return `${splitStr[0]}.${splitStr[1].slice(0, 4)}`;
} else {
return `${splitStr[0]}.${splitStr[1].slice(0, 8)}`;
}
};
There was no problem with the input output value through the logic I made myself.
An issue occurs in the view group only through priceFormat.