Closed JGSolutions closed 8 years ago
You can use .getChart()
on the chart element then you have the myLineChart
instance.
var ChartElement = (<LineChart data={data} />);
vart chart = ChartElement.getChart();
chart.generateLegend();
@Dallas62, does your example still work in the latest react version?
@queimadus I'm using react 0.13.3 and it seems to work. But the legend isn't a ReactElement.
@Dallas62, my question specifically is if you can access the getChart()
method before the ChartElement
is rendered by the render
method.
I managed to access the chart
by rendering the ChartElement
with a ref
and then doing this.refs.chart.state.getChart()
in the componentDidMount
e.g..
How are you accessing the chart? Could you give an example?
Ideally, I'd like to render the ChartElement
and the generateLegend()
html right away in the render()
function without having to use componentDidMount
and using the approach described above.
@queimadus I do not use generateLegend()
in my case, I generate the legend myself.
I just answered to the question: How can I use this method?
@Dallas62 so you don't access the underlying chart
object from chart.js encapsulated in the ChartElement
at all.
You generate the legend from the data
you pass as props to the ChartElement
. Is that it?
Exactly
How can I use this method?
From the chart.js site: var myLineChart = new Chart(ctx).Line(data); myLineChart.generateLegend();
Since react.js is rendering the pie chart.