cYn
cYn

Reputation: 3381

Highchart only wants "y" element in JSON data?

First here is my JSFiddle: http://jsfiddle.net/H242k/1/

It seems as though if I feed Highcharts a JSON data, it wants the "value" to be an element "y". But the JSON data I'm pulling is an arbitrary value element.

In my JSFiddle, if I change "Results of Last Year" to "y", it works. How do I make it so that it will take "Results of Last Year" as the chart's value?

Also, if I structure my data like this, how do I access the category (cat1, cat2, cat3, etc) in the xAxis label?

Upvotes: 0

Views: 49

Answers (1)

Barbara Laird
Barbara Laird

Reputation: 12717

Highcharts is reading your structure and creating a chart with it. You can't just come up with whatever structure you want and expect Highcharts to know what to do with it. The available options are very well documented at http://api.highcharts.com/. To define a point, look at the http://api.highcharts.com/highcharts#series.data. If you want to use text instead of numbers for your xAxis, use categories http://api.highcharts.com/highcharts#xAxis.categories.

In your case, something like this will work:

  $('#container').highcharts({
        xAxis: {
            categories: ['cat1', 'cat2', 'cat3', 'cat4', 'cat5', 'cat6', 'cat7', 'cat8', 'cat9', 'cat10', 'cat11', 'catr12']
        },
        series: [{
            data: [29.9, 71.5,106.4,129.2,144.0,176.0,135.6,148.5,216.4,194.1,95.6,54.4]
        }]
    });

http://jsfiddle.net/H242k/2/

Upvotes: 1

Related Questions