angular-chart.js icon indicating copy to clipboard operation
angular-chart.js copied to clipboard

directive -> directive -> chart :: Does not render

Open randycasburn opened this issue 9 years ago • 8 comments

https://plnkr.co/edit/cHSkSfmHI0WW7TS5Krwr?p=preview

The use case: Dynamically add charts based upon a directive setting.

First directive declares type of chart to be created inside the second directive The second directive dynamically compiles a third directive The third directive has controller that has data/config for chart.

No js errors and templates are rendered properly. Chrome Batarang shows the chart's full angular model has been created. But chart does not show.

randycasburn avatar Jul 13 '16 01:07 randycasburn

I had the same issue. I solve this by modifying my directive template. I think the size of the outer html element was too small.

here is my before -> after using bootstrap css:

Before:

<canvas class="chart chart-line" chart-data="data"
chart-labels="labels" chart-series="series" chart-options="options"
chart-dataset-override="datasetOverride" chart-click="onClick">
</canvas>

After:

<div class="row">
    <div class="cold-md-12">
        <canvas class="chart chart-line" chart-data="data"
        chart-labels="labels" chart-series="series" chart-options="options"
        chart-dataset-override="datasetOverride" chart-click="onClick">
        </canvas>
    </div>
</div>

GuiSevero avatar Jul 26 '16 19:07 GuiSevero

Similar to what @GuiSevero found, the canvas element does not wrap itself in a <div> the way that the 0.x releases did, so code that worked like this in 0.x:

<canvas class="chart chart-line" chart-data="vm.chartData" 
chart-labels="vm.chartLabel" chart-series="vm.chartSeries"></canvas>

Now requires being wrapped in a <div>:

<div>
   <canvas class="chart chart-line" chart-data="vm.chartData" 
    chart-labels="vm.chartLabel" chart-series="vm.chartSeries"></canvas>
</div>

nerdoza avatar Aug 12 '16 21:08 nerdoza

Works for me !! from:

<canvas width="400" height="200" class="chart chart-bar" chart-click="vm.graphicOnClick" chart-data="vm.graphicData" chart-labels="vm.graphicLabels" chart-series="vm.graphicSeries"></canvas>

to

`

`

the directive was included in bootstrap structure: `

`

jromerob avatar Oct 03 '16 11:10 jromerob

Wrapping in a div works perfectly! I needed to do this in a Component in Angular 1.5.8 to get it to render. Should this be added to the docs?

seanlindo avatar Oct 12 '16 18:10 seanlindo

This solved my problem! Thanks!

lucas-barros avatar Oct 19 '16 13:10 lucas-barros

Had the same problem working with ui-router, the charts are in a state and I thought the problem was with rendering the chart before it was fully loaded, but the solution was just adding a "div" tag wrapper for the chart. Thanks for the solution !!!

marcelo-s avatar Nov 01 '16 16:11 marcelo-s

Found the same issue, basically using nested components, to make a modular dashboard, and the directives were individual panels. Had me scratching my head for most of the day.

Maraket avatar Nov 07 '16 09:11 Maraket

This is the most awkward fix I've ever encountered. Thanks for sharing.

jasperdj avatar Nov 25 '16 09:11 jasperdj