Thank you again! Yes, I’ve checked and each div has a unique ID to render the charts. I’ve spent some time investigating it and I think I am getting closer to the problem. I have this:
//chartsArray
[{"chartLabel": "DIV01", "chartInfo": [{}], "carteiraDataSet": [{...}], "benchmarkDataSet": [{...}]},{"chartLabel":"DIV02", "chartInfo": [{}], "carteiraDataSet": [{...}], "benchmarkDataSet": [{...}]},{"chartLabel":"DIV03", "chartInfo": [{}], "carteiraDataSet": [{...}], "benchmarkDataSet": [{...}]},{"chartLabel":"DIV04", "chartInfo": [{}], "carteiraDataSet": [{...}], "benchmarkDataSet": [{...}]},{"chartLabel":"DIV05", "chartInfo": [{}], "carteiraDataSet": [{...}], "benchmarkDataSet": [{...}]}]
//chart-loader.hbs - It fetches the charts data and put it inside chartsArray
{{#each this.chartsArray as |chart|}}
<LineChart @carteiraDataSet={{chart.carteiraDataSet}} @benchmarkDataSet={{chart.benchmarkDataSet}} @chartId={{chart.chartLabel}} />
{{/each}}
Even though the chartsArray
has different data set to each chart, I end up with 5 equal charts when the rendering finishes.
LineChart
component renders the chart like this:
//line-chart-hbs
<div class="justify-center">
{{#if this.isLoading}}
... loading
{{else}}
<div class="start-chart"
{{did-insert this.buildChart}}>
</div>
<div class="justify-center" id={{@chartId}}></div>
{{/if}}
</div>
Every time it is calling buildChart
to build the chart. I am suspecting that when I call did-insert
it overrides everything, it builds each chart again with the current data on the loop. I am right now thinking how to write the same logic without using did-insert
to see if it works.
What do you think? Does that make sense?
But it doesn’t explain why the chart’s info (that is just some strings) is also being overwritten. Inside the chartArray
there is also some info about the chart that is inside chartInfo
. And then, inside the loop I am trying to render it:
//chart-loader.hbs
{{#each this.chartsArray as |chart|}}
<LineChart @carteiraDataSet={{chart.carteiraDataSet}} @benchmarkDataSet={{chart.benchmarkDataSet}} @chartId={{chart.chartLabel}} />
<ChartInfo @info={{chart.chartInfo}}/>
{{/each}}
//chart-info.hbs
<span class="inline-block text-sm font-bold">{{@info.chartLabel}}</span>
<p>{{@info.description}}</p>
<p><b>Data de inĂcio:</b> {{moment-format @info.startDate "DD/MM/YYYY"}}</p>
But at the end all charts info is also the same (the last one on the loop).