chartist-js / chartist

Simple responsive charts
https://chartist.dev
MIT License
13.34k stars 2.53k forks source link

Update dynamically referenced chart div #1319

Open sll1966 opened 2 years ago

sll1966 commented 2 years ago

I have a dashboard for various production lines (obtained from a DB) The code adds appropriate DIV's in a forEach called function. <div id="ChartTrend${MyLine}" class="ct-chart" style="width: 99%; height: 90%; "></div> Then tries to put in a chart (no real data yet) eval("var ChartTrend" + MyLine + " = new Chartist.Line('#ChartTrend' + MyLine ,dummydata , optionsLine); "); or window["ChartTrend" + MyLine] = new Chartist.Line('#ChartTrend' + MyLine,dummydata,optionsLine);

In debugger, i see the ChartTrend1-8 div created. Only ChartTrend9 (the last) actually displays the chart with dummy data console.log(document.getElementById(ChartTrend${MyLine}).children ); shows chart with data created for each line though.

Then once above is working, go get data and fill it in async function like below,

window['ChartTrend' + MyLine].update(chartdata);

but i get "Uncaught TypeError: window[("ChartTrend" + MyLine)].update is not a function"