Commit 7a35b967 authored by 崔佳豪's avatar 崔佳豪

fix: 基本图表接收额外参数

parent 8a1e38fb
...@@ -22,7 +22,9 @@ const gradientColors = [ ...@@ -22,7 +22,9 @@ const gradientColors = [
]), ]),
); );
const BarChart = forwardRef(({ category, dataSource }, ref) => { const BarChart = forwardRef((props, ref) => {
const { category, dataSource } = props;
const option = useMemo(() => { const option = useMemo(() => {
const xAxis = isCategory(category) const xAxis = isCategory(category)
? { ? {
...@@ -50,7 +52,9 @@ const BarChart = forwardRef(({ category, dataSource }, ref) => { ...@@ -50,7 +52,9 @@ const BarChart = forwardRef(({ category, dataSource }, ref) => {
return { xAxis, yAxis, series }; return { xAxis, yAxis, series };
}, [category, dataSource]); }, [category, dataSource]);
return <ECharts ref={ref} option={option} />; const restProps = _.omit(props, ['category', 'dataSource']);
return <ECharts ref={ref} option={option} {...restProps} />;
}); });
BarChart.PropTypes = { BarChart.PropTypes = {
......
...@@ -5,7 +5,8 @@ import _ from 'lodash'; ...@@ -5,7 +5,8 @@ import _ from 'lodash';
const isCategory = (category) => category !== undefined; const isCategory = (category) => category !== undefined;
const isArea = (lineType) => lineType === 'area'; const isArea = (lineType) => lineType === 'area';
const LineChart = forwardRef(({ category, lineType, smooth, dataSource, title }, ref) => { const LineChart = forwardRef((props, ref) => {
const { category, lineType, smooth, dataSource, title } = props;
const option = useMemo(() => { const option = useMemo(() => {
const titleCfg = typeof title === 'string' ? { show: true, text } : { show: false }; const titleCfg = typeof title === 'string' ? { show: true, text } : { show: false };
const xAxis = isCategory(category) const xAxis = isCategory(category)
...@@ -35,7 +36,9 @@ const LineChart = forwardRef(({ category, lineType, smooth, dataSource, title }, ...@@ -35,7 +36,9 @@ const LineChart = forwardRef(({ category, lineType, smooth, dataSource, title },
return { xAxis, yAxis, series, title: titleCfg }; return { xAxis, yAxis, series, title: titleCfg };
}, [category, smooth, lineType, dataSource, title]); }, [category, smooth, lineType, dataSource, title]);
return <ECharts ref={ref} option={option} />; const restProps = _.omit(props, ['category', 'lineType', 'smooth', 'dataSource', 'title']);
return <ECharts ref={ref} option={option} {...restProps} />;
}); });
LineChart.PropTypes = { LineChart.PropTypes = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment