Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts X-axis labels on the side

I'm using Highcharts, and I used to be able to get labels on the side. But it's not working now, am I missing something? The red arrow is where I would want the labels like in the following example.

http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/bar-basic/

enter image description here

This is the code I'm using, I add the series in a dynamic way.

 credits: {
                enabled: false
            },
            chart: {
                type: 'bar'
            },
            xAxis: {
                categories: ['Jan', 'Feb'],
                labels: {
                    enabled: true,
                }
            },
            yAxis: {
                min: 0,
                max: 100,
                title: {
                    text: 'Score',
                    align: 'high'
                }
            },
            plotOptions: {
                bar: {
                    dataLabels: {
                        enabled: true
                    }
                }
            }
        });

        // Add Series
        var detailchart = $('#chart-detail').highcharts();
        var categories = new Array;

        // Set Chart Title
        detailchart.setTitle({text: results[0].category});

        $.each(results, function(i, data){
            categories.push(data.name);
            detailchart.addSeries({
                name: data.name,
                data: [data.score]
            });
        });

        detailchart.xAxis[0].setCategories(["1", "2"]);
        $('#chart-detail').highcharts().reflow();

Results is an array that looks like this (I get it through ajax):

enter image description here

like image 796
Miguel Stevens Avatar asked Apr 29 '15 15:04

Miguel Stevens


People also ask

How do you rotate the X axis labels in Highcharts?

I use : xAxis: { labels: { rotation: -45, align: 'top' }, categories: xAxisLabel }, for rotate the xaxis labels when number of labels are large.

What is the label of the X axis?

Horizontal axis labels represent the X axis. They do not apply to pie, funnel, or gauge charts. Vertical axis labels represent the Y1 axis in a single axis chart. They represent a numeric scale, usually located on the left side of a vertical chart.

What is tick interval in Highcharts?

The width of the grid lines extending the ticks across the plot area. Defaults to 1 on the Y axis and 0 on the X axis, except for 3d charts. In styled mode, the stroke width is given in the . highcharts-grid-line class.


1 Answers

As I understand from your code here, you wish to specify two categories with names 1 and 2 but you are not specifying any data for second category, So the only category that is showing on your chart is 1. Your data array for each series must have elements per each category. For example if you have two category you should consider having two data elements in each series. In this line data: [data.score] you are just specifying one element in data array. Your code should be something like this: (make it dynamic per your need)

$.each(results, function(i, data){
        categories.push(data.name);
        detailchart.addSeries({
            name: data.name,
            data: [data.score, 40], //40 is some data for your second category.
        });
    });

Demo: http://jsfiddle.net/u6crkatv/

like image 100
Iman Kianrostami Avatar answered Oct 08 '22 02:10

Iman Kianrostami