Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do in Highchart to have 1px space between the columns and the y Axis?

I have to do a column chart using highcharts that has 1px space between the colums and the Y axis, how can I add the 1px space that is in my desired chart to the chart I did, these is the code I did: (Sorry I don't have the reputation enough to add images that's why I haven't post then)

var data = [ 20, 29, 25, 29, 21, 17, 20, 19, 18]; 
createMeasuresGraph(data, "quintals-sugar-graph");
function createMeasuresGraph(data, container) {
    data[0] = { color: '#55B647', y: data[0] };
    data[data.length -2 ] = { color: '#F15B49', y: data[data.length -2 ] };
    var chart = new Highcharts.Chart({
        chart: {
            marginBottom: 1,
            marginLeft: 0,
            marginRight: 0,
            marginTop: 0,
            renderTo: container,
            type: 'column',
        },
        credits: {
            enabled: false
        },
        legend: {
            enabled: false
        },
        plotOptions: {
            column: {
                pointWidth: 5,
            },
            series: {
                borderWidth: .1,

            }
        },
        series: [{
            data: data,
            color: '#95D2F3',
            shadow: false,
        }],
        title: {
            text: ''
        },
        tooltip: {
            enabled: false
        },
        xAxis: {
            labels: {
                enabled: false
            },
            title: {
                enabled: false
            },
            lineColor: '#CBCBCB',
            tickWidth: 0
        },
        yAxis: {
            endOnTick: false,
            gridLineWidth: 0,
            labels: {
                enabled: false
            },
            startOnTick: false,
            minPadding: 0.5,
            title: {
                text: ""
            }
        }
    });
}

I seeing also that the space between is not the same in all the columns, maybe I'm using a wrong aproch to get the spaces, what would it be best?

like image 691
mkhuete Avatar asked Sep 03 '12 15:09

mkhuete


People also ask

How do I set margins in Highcharts?

Use the options marginTop , marginRight , marginBottom and marginLeft for shorthand setting of one option. By default there is no margin.

How do I reduce the gap between bars in Highcharts?

Re: Reducing the space between the bars (column range) You can for example lower the max property value (or change extremes with Axis. setExtremes()) to reduce the visible range and this way you can retain fixed pointWidth and increase space between tick at the same time.

What is plotOptions in Highcharts?

The plotOptions is a wrapper object for config objects for each series type. The config objects for each series can also be overridden for each series item as given in the series array. Configuration options for the series are given in three levels. Options for all series in a chart are given in the plotOptions.

What is y axis in chart?

Charts typically have two axes that are used to measure and categorize data: a vertical axis (also known as value axis or y axis), and a horizontal axis (also known as category axis or x axis).


2 Answers

You want a 1px space between each column?

I would calculate the column width based on the size of the plot / number of columns:

var colWidth = ($('#quintals-sugar-graph').width() / data.length) + 1;

Then set the "borderWidth" to 1px to provide the space:

    plotOptions: {
        column: {
            pointWidth: colWidth,
            borderWidth: 1
        },

    },

Fiddle here.

enter image description here

like image 87
Mark Avatar answered Sep 20 '22 23:09

Mark


Do you really need the width to be exactly 1px? If not, the following also leave minimum space between columns and would be more convenient:

plotOptions: {
    column: {
        pointPadding: 0,
        groupPadding: 0
    }
}
like image 29
ricca Avatar answered Sep 18 '22 23:09

ricca