Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dynamically referenced chart div #1319

Open
sll1966 opened this issue Jul 13, 2022 · 0 comments
Open

Update dynamically referenced chart div #1319

sll1966 opened this issue Jul 13, 2022 · 0 comments
Labels

Comments

@sll1966
Copy link

sll1966 commented Jul 13, 2022

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"

@sll1966 sll1966 changed the title Only last chart updated from eval statement Update dynamically referenced chart div Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants