Simon
Simon

Reputation: 708

Update data on an amChart graph from data within a DIV element

I am having some problems with my JavaScript and amCharts graph.

What I am trying to achieve is to reload an amChart line graph with new data from a DIV element. In my final page this DIV element will be dynamically updated and hidden so will not been seen by the end user. The graph needs to be redrawn without reloading the page.

I have an JSFiddle page with an example of my attempts to reload the data.

http://jsfiddle.net/gnuoynomis/Se2UE/1/

I have tried to:

My reset of the graph works perfectly if I add the entire string straight in manually and this is what I am trying to replicate with the other methods.

If anyone is able to point out what I am doing wrong then I would be most grateful. I am also open to any suggestions if you think that I could be doing this in a better way.

Upvotes: 1

Views: 7050

Answers (1)

faby
faby

Reputation: 7566

working fiddle

http://jsfiddle.net/Se2UE/2/

the core of my change is here

var NewChartDataArray = [];
  for(i=0; i<CD.length; i++)
  {
    var D = CD[i];
    D = D.replace("{","");
    D = D.replace("}","");
    D = "{" + D + "}";

    NewChartDataArray.push(JSON.parse(D));
  }

declare NewChartDataArray as array and not string then add an object to array. You had an array of strings, your library expects an array of objects

refer this

Upvotes: 2

Related Questions