From 071e3582728a67e14f17041a386981668b7df4f4 Mon Sep 17 00:00:00 2001 From: Doma Date: Thu, 16 Jun 2022 17:28:54 +0800 Subject: [PATCH] fix(Legend): fix not getting data from dataset --- src/charts/BarChart.tsx | 19 ++++++------------- src/utils.ts | 14 +++++++------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/charts/BarChart.tsx b/src/charts/BarChart.tsx index cc10222..c1669b3 100644 --- a/src/charts/BarChart.tsx +++ b/src/charts/BarChart.tsx @@ -10,11 +10,11 @@ import { EChartsContext } from '../constants'; const categoryAxisProps: any = { type: 'category', - splitLine: false, + splitLine: false }; const valueAxisProps: any = { - type: 'value', + type: 'value' }; interface BarChartProps extends ChartComponentProps { @@ -70,18 +70,11 @@ function BarChart( function renderDefaultSeries() { // 水平图表从上往下阅读则需将 data 翻转过来 const data = horizontal ? [...inputData!].reverse() : inputData!; - const values = data.map((d) => d[1]); + const values = data.map(d => d[1]); return ; } - function renderDefaultLegend() { - const components = Children.toArray(children); - const series = components.filter(isSeries); - const dataNames = series.length ? series.map((serie: any) => serie.name) : [name]; - return ; - } - const components = Children.toArray(children); const series = components.filter(isSeries); @@ -101,13 +94,13 @@ function BarChart( {!categoryAxis && renderDefaultCategoryAxis()} {!valueAxis && renderDefaultValueAxis()} {!components.find((comp: any) => is(comp, 'bars')) && renderDefaultSeries()} - {legend && !components.find((comp: any) => is(comp, 'legend')) && renderDefaultLegend()} + {legend && !components.find((comp: any) => is(comp, 'legend')) && } {tooltip && } {components.map((child: any) => { if (child.type === (horizontal ? YAxis : XAxis)) { return cloneElement(child, { ...categoryAxisProps, - data: child.props.data || data!.map(([category]) => category), + data: child.props.data || data!.map(([category]) => category) }); } if (child.type === (horizontal ? XAxis : YAxis)) { @@ -115,7 +108,7 @@ function BarChart( } if (data!.length && isSeries(child) && !child.props.data) { const serieIndex = series.indexOf(child); - return cloneElement(child, { data: data!.map((d) => d[serieIndex + 1]) }); + return cloneElement(child, { data: data!.map(d => d[serieIndex + 1]) }); } return child; })} diff --git a/src/utils.ts b/src/utils.ts index 378d615..ef3ff32 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -118,16 +118,16 @@ const createOptions = { }, [symbols.legend](option: any, props: any, context: any) { function getOption() { - const { chartType, series, chartData = [] } = context; + const { chartType, } = context; let legendOption: any = { show: true, bottom: 10, - data: - chartType === 'pie' - ? chartData.map(([name]: any) => name) - : series.map((comp: any) => { - return comp.props.name; - }), + // data: + // chartType === 'pie' + // ? chartData.map(([name]: any) => name) + // : series.map((comp: any) => { + // return comp.props.name; + // }), }; if (chartType === 'pie') {