Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X-axis category name from string in series list

Tags:

highcharts

Is it possible to get the x-axis names from a string in my series list? I'm building this series list on the backend and would like to use the "New York", "LA" and "Chicago" as my x-axis category values.

I would expect "New York", "LA" and "Chicago" as my x-axis labels, however, I'm getting -0.25 through 2.25.

Thanks.

http://jsfiddle.net/nicholasduffy/H7zgb/2/

$(function () {
var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        type: 'column'
    },
    plotOptions: {
        column: {
            stacking: 'normal',
            dataLabels: {
                enabled: false
            }
        }
    },
    series: [{
        "data": [
            ["New York", 3570.5],
            ["LA", 50128.38],
            ["Chicago", 5281.22]
        ],
        "name": "Stuff"
    }, {
        "data": [
            ["New York", 10140.84],
            ["LA", 21445.04],
            ["Chicago", 12957.77]
        ],
        "name": "Junk"
    }, {
        "data": [
            ["New York", 65119.6],
            ["LA", 103118.6],
            ["Chicago", 78349.6]
        ],
        "name": "Other Stuff"
    }]
});

});

like image 249
duffn Avatar asked Mar 19 '13 21:03

duffn


2 Answers

As of HighCharts 3 you can use xAxis.type and set it to "category" for your desired behavior without having to specify the category names.

http://api.highcharts.com/highcharts#xAxis.type

I've edited the jFiddle to have the following:

xAxis: {
        type: "category"
    }

http://jsfiddle.net/H7zgb/22/

like image 84
acvcu Avatar answered Oct 20 '22 18:10

acvcu


I believe you are looking for this...

http://api.highcharts.com/highcharts#xAxis.categories

Take a look at this fiddle...I've added the following:

    xAxis: {
        categories: ["New York", "LA", "Chicago"]
    },

http://jsfiddle.net/H7zgb/3/

like image 2
Frank Reno Avatar answered Oct 20 '22 20:10

Frank Reno