Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts X-Axis labels as Text

In this fiddle, with out changing the series data, Is it possible to show x-axis labels as text i.e. {"apple","orange","mango"} instead of decimals i.e {0,1,2} with out separating labels from JSON and providing it to Categories.

$(function () {
    $('#container').highcharts({
        chart: {
        },
        xAxis: {

            labels: {
                enabled: true
            }
        },

        series: [{
            data: [["apple",29.9], ["orange",71.5], ["mango",106.4]]        
        }]
    });
});
like image 220
Srinivas Avatar asked Oct 15 '13 12:10

Srinivas


2 Answers

Try this:

 $(function () {

var seriesData = [["apple",29.9], ["orange",71.5], ["mango",106.4]];     
$('#container').highcharts({
    chart: {
    },
    xAxis: {
        tickInterval: 1,
        labels: {
            enabled: true,
            formatter: function() { return seriesData[this.value][0];},
        }
    },

    series: [{
        data: seriesData     
     }]
  });
});

SEE DEMO

like image 107
Nitish Kumar Avatar answered Oct 03 '22 10:10

Nitish Kumar


You can use catgories in xAxis

xAxis: {
    categories: ["apple", "orange", "mango"],
}

I've updated your fiddle: http://jsfiddle.net/Lq6me/1/

If you don't want to use categories you can go for

labels: {
    formatter: function() {}
}
like image 41
Strikers Avatar answered Oct 03 '22 11:10

Strikers