Monday 16 October 2017

javascript - Format data to parse to a highcharts pie chart

itemprop="text">

I have an app that fetches json data
of the largest stock movers in a day from a google spreadsheet. I then use this data to
generate a pie chart showing the different movers and the number of shares sold using
ajax to populate the chart



Here is my
code:







NSE VISUALIZATIONS
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">

src="highcharts.js">












The
data format recognised by highcharts is as
follows:




[["SCOM",2392492],["EQTY",2089121]]



I
however have this as my data in 2 arrays: the first being a set of largest mover names
and the second being a list of their values arranged in the respective order in which
the mover names are arranged in the first array.
i.e.




["SCOM","EQTY"]

[2392492,
2089121]


How should I
format my code to take in this 2 array and relate them to plot a pie
chart



Answer





You can simply match arrays, for
example:



 var points =
[],
mv = this.mover;
$.each(this.moverValue, function(i ,e)
{
points[i] = [mv[i],e];
})

this.chart1.data.series[0].data =
points;



Demo:
rel="nofollow">http://jsfiddle.net/9Yjc4/3/



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...