From 0de7b8bbf30a655494414114d58c5e07dd577101 Mon Sep 17 00:00:00 2001 From: zpz1982 Date: Tue, 9 May 2017 08:43:44 +0800 Subject: [PATCH] add onChartReady function prop It is easy to get chart instance , useful when need save chart. --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 404270d..b61548a 100644 --- a/src/index.js +++ b/src/index.js @@ -46,7 +46,7 @@ export default function createG2(__operation) { } initChart(props) { - const { width, height, data, plotCfg, forceFit, configs } = props; + const { width, height, data, plotCfg, forceFit, configs, onChartReady } = props; const chart = new G2.Chart({ id: this.chartId, width, height, @@ -55,6 +55,7 @@ export default function createG2(__operation) { }); chart.source(data); __operation(chart, configs); + if (typeof onChartReady === 'function') onChartReady(chart); this.chart = chart; } @@ -70,6 +71,7 @@ export default function createG2(__operation) { plotCfg: React.PropTypes.object, forceFit: React.PropTypes.bool, configs: React.PropTypes.object, + onChartReady: React.PropTypes.func, }; return Component;