Highcharts 固定布局柱形图
下图是一个 Highcharts 固定布局柱形图
配置
-
配置属性 series.pointPadding 用于控制每列之间的距离值,默认值为 0.1
当 highcharts 图表宽度固定的情况下,此值越大,柱子宽度越小,反之相反
-
配置属性 series.pointPlacement 用于控制 X 轴上的点之间的距离
在柱形图中,当 pointPlacement 设置为 "on" 时, X轴上的点没有间隔
如果 pointPlacement 设置为 "between", 列之间按刻度进行布局
在 Highcharts 3.0.2 后的版本, pointPlacement 可以支持数字,0 为轴上的值, -0.5 为当前值与前面一个值的间隔, 0.5 为 当前值与下一个值的间隔
不同与文字设置选项,数字设置不影响轴之间的间隔
series: { name: 'Employees', color: 'rgba(165,170,217,1)', data: [150, 73, 20], pointPadding: 0.3, pointPlacement: -0.2 }
范例
下面的代码列出了 Highcharts 固定布局柱形图 的基本配置
<!doctype html> <meta charset="utf-8" /> <title>Highcharts 基础教程 | 简单教程(www.twle.cn)</title> <script src="https://cdn.hcharts.cn/highcharts/highcharts.js"></script> <div id="container" style="width: 500px; height: 400px; margin: 0 auto"></div> <script> var chart = { type: 'column' }; var title = { text: 'Efficiency Optimization by Branch' }; var xAxis = { categories: ['Seattle HQ', 'San Francisco', 'Tokyo'] }; var yAxis = [{ min: 0, title: { text: 'Employees' } }, { title: { text: 'Profit (millions)' }, opposite: true }]; var legend = { shadow: false }; var tooltip = { shared: true }; var credits = { enabled: false }; var plotOptions = { column: { grouping: false, shadow: false, borderWidth: 0 } }; var series= [{ name: 'Employees', color: 'rgba(165,170,217,1)', data: [150, 73, 20], pointPadding: 0.3, pointPlacement: -0.2 }, { name: 'Employees Optimized', color: 'rgba(126,86,134,.9)', data: [140, 90, 40], pointPadding: 0.4, pointPlacement: -0.2 }, { name: 'Profit', color: 'rgba(248,161,63,1)', data: [183.6, 178.8, 198.5], tooltip: { valuePrefix: '$', valueSuffix: ' M' }, pointPadding: 0.3, pointPlacement: 0.2, yAxis: 1 }, { name: 'Profit Optimized', color: 'rgba(186,60,61,.9)', data: [203.6, 198.8, 208.5], tooltip: { valuePrefix: '$', valueSuffix: ' M' }, pointPadding: 0.4, pointPlacement: 0.2, yAxis: 1 }]; var options = {}; options.chart = chart; options.title = title; options.xAxis = xAxis; options.yAxis = yAxis; options.tooltip = tooltip; options.credits = credits; options.series = series; options.legend = legend; options.plotOptions = plotOptions; var chart = Highcharts.chart('container',options); </script>
以上范例输出如下