最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Sep 16, 2013 at 3:19 SheetJS 22.9k12 gold badges67 silver badges76 bronze badges asked Sep 3, 2012 at 15:25 mkhuetemkhuete 8532 gold badges7 silver badges9 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 13

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.

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
    }
}

You can simply do:

plotOptions: {
  column: {
    pointPadding: 0,
    groupPadding: 0,
    borderWidth: 1
  }
},
发布评论

评论列表(0)

  1. 暂无评论