fix: split line align for two yAxis chart
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import { throttle } from 'lodash';
|
import { throttle } from 'lodash';
|
||||||
import React, {
|
import React, {
|
||||||
forwardRef,
|
forwardRef,
|
||||||
useCallback,
|
|
||||||
useEffect,
|
useEffect,
|
||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
useRef
|
useRef
|
||||||
@@ -26,27 +25,24 @@ const Chart: React.FC<{
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const init = useCallback(() => {
|
const init = () => {
|
||||||
if (container.current) {
|
if (container.current) {
|
||||||
chart.current?.clear();
|
chart.current?.clear();
|
||||||
chart.current = echarts.init(container.current);
|
chart.current = echarts.init(container.current);
|
||||||
}
|
}
|
||||||
}, []);
|
};
|
||||||
|
|
||||||
const resize = useCallback(() => {
|
const setOption = (options: ECOption) => {
|
||||||
chart.current?.resize();
|
console.log('setOption', options);
|
||||||
}, []);
|
chart.current?.clear();
|
||||||
|
chart.current?.setOption(options, {
|
||||||
const setOption = useCallback(
|
notMerge: true,
|
||||||
(options: ECOption) => {
|
lazyUpdate: true
|
||||||
chart.current?.clear();
|
});
|
||||||
chart.current?.setOption(options, {
|
if (Array.isArray(options.yAxis) && options.yAxis.length > 1) {
|
||||||
notMerge: true,
|
chart.current?.resize();
|
||||||
lazyUpdate: true
|
}
|
||||||
});
|
};
|
||||||
},
|
|
||||||
[options]
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleOnFinished = () => {
|
const handleOnFinished = () => {
|
||||||
@@ -55,12 +51,6 @@ const Chart: React.FC<{
|
|||||||
const currentChart = chart.current;
|
const currentChart = chart.current;
|
||||||
const optionsYAxis = currentChart.getOption()?.yAxis;
|
const optionsYAxis = currentChart.getOption()?.yAxis;
|
||||||
|
|
||||||
console.log(
|
|
||||||
'chart finished',
|
|
||||||
finished.current,
|
|
||||||
optionsYAxis,
|
|
||||||
chart.current
|
|
||||||
);
|
|
||||||
if (
|
if (
|
||||||
!optionsYAxis ||
|
!optionsYAxis ||
|
||||||
!Array.isArray(optionsYAxis) ||
|
!Array.isArray(optionsYAxis) ||
|
||||||
@@ -106,11 +96,9 @@ const Chart: React.FC<{
|
|||||||
}
|
}
|
||||||
finished.current = true;
|
finished.current = true;
|
||||||
|
|
||||||
setTimeout(() => {
|
currentChart.setOption({
|
||||||
currentChart.setOption({
|
yAxis: yAxis
|
||||||
yAxis: yAxis
|
});
|
||||||
});
|
|
||||||
}, 0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (container.current) {
|
if (container.current) {
|
||||||
@@ -122,15 +110,14 @@ const Chart: React.FC<{
|
|||||||
chart.current?.dispose();
|
chart.current?.dispose();
|
||||||
chart.current?.off('finished', handleOnFinished);
|
chart.current?.off('finished', handleOnFinished);
|
||||||
};
|
};
|
||||||
}, [init]);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resizeable.current = false;
|
resizeable.current = false;
|
||||||
finished.current = false;
|
finished.current = false;
|
||||||
resize();
|
|
||||||
setOption(options);
|
setOption(options);
|
||||||
resizeable.current = true;
|
resizeable.current = true;
|
||||||
}, [setOption]);
|
}, [options]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleResize = throttle(() => {
|
const handleResize = throttle(() => {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ interface RequestTokenData {
|
|||||||
|
|
||||||
const DefaultDateConfig = {
|
const DefaultDateConfig = {
|
||||||
maxRange: 60,
|
maxRange: 60,
|
||||||
defaultRange: 30
|
defaultRange: 29
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLast30Days = () => {
|
const getLast30Days = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user