K
K
Kirill Gorelov2017-02-25 16:59:11
JSON
Kirill Gorelov, 2017-02-25 16:59:11

Charts in highcharts display data?

Hello.
I am building a chart in highcharts. Almost everything works out. And I can read the json format and display a specific value, but the graph is not built. I reviewed a bunch of examples, it almost turns out that it’s not enough just to display the data on the chart.

$(function () {
    var data12 = '[{"0":{"fl":"266"},"1":{"freelance":"1"},"2":{"freelancejob":"3"},"3":{"weblancer":"38"},"col_day":"308","day_budjet":"2864769","col_mount":"5185","day_budjet_mount":"21541027","chart_arr_fl":["30","968","1372","608","820","266"],"chart_arr_freelance":["6","7","3","19","54","1"],"chart_arr_freelancejob":["45","8","11","4","13","3"],"chart_arr_freelansim":["25","39","19","5","11"],"chart_arr_weblancer":["80","199","252","120","159","38"]}]';
   // $('#btn').click(function(){
        var val1,
            val2,
            splitted,
            options;
        var seriesData = [],
      data = JSON.parse(data12);
      console.log(data);
        for (var i = 0; i < data.length; i++) {
  //alert( 'Вам сообщение ' + splitted[i] );
  seriesData.push(data[i].chart_arr_fl);
}
alert(seriesData);
        options = {
            series: [{
                name: 'Browser share',
              data: seriesData
            }]
        };
        $('#container').highcharts(options); 
});

Now alert(seriesData); = 30,968,1372,608,820,266
And when I substitute it in data ->(data: seriesData) the graph is not built, guys, tell me what to do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2017-02-25
@Kirill-Gorelov

The data array must contain numbers, and you have string representations.
Feel the difference:

["30", "968", "1372", "608", "820", "266"]
[30, 968, 1372, 608, 820, 266]

Plus a logical error in data processing. In short, here is a working version -
jsfiddle.net/6cfg06q8
Or so jsfiddle.net/6cfg06q8/1

A
Artem, 2017-11-07
@proudmore

Forget about files, it's too confusing to search, update, delete, and so on. Just imagine the amount of code it would take.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question