gpt4 book ai didi

javascript - 使用highchart在柱形图中隐藏列后如何填充空间?

转载 作者:行者123 更新时间:2023-11-30 11:51:35 25 4
gpt4 key购买 nike

有没有办法在点击图例项目隐藏一列后填充空间?

<div id="container" style="height: 300px"></div>
<script src="http://code.highcharts.com/highcharts.src.js"></script>

var chart = new Highcharts.Chart({

chart: {
type: 'column',
renderTo: 'container'
},

"title":{
"text":"TITLE",
"align":"left"
},
"subtitle":{
"text":"Subtitle Text",
"align":"left",
"style":{
"paddingBottom":"20px"
}
},
"xAxis":{
"categories":[
"Category1",
"Category2",
"Category3",
"Category4",
"Category5"
],
"crosshair":true,
"title":{

},
"labels":{
"enabled":false,
"format":"{value}"
}
},
"yAxis":{
"min":0,
"title":{
"text":"Meters"
},
"labels":{
"format":"{value}"
}
},
"tooltip":{
"enabled":true,
"headerFormat":"<span style=\"font-size:10px\">{point.key}</span><br/>",
"shared":true,
"useHTML":true
},
"legend":{
"enabled":true,
"align":"left",
"useHTML":true
},
"plotOptions":{
"column":{
"pointPadding":0.2,
"borderWidth":0,
"dataLabels":{
"enabled":true,
"format":"{point.y:.2f} ",
"style":{
"textShadow":0
}
}
},
"series":{
"grouping":false
}
},
"series":[
{
"name":"Category1",
"data":[
{
"name":"Category1",
"y":45,
"x":0
}
]
},
{
"name":"Category2",
"data":[
{
"name":"Category2",
"y":43,
"x":1
}
]
},
{
"name":"Category3",
"data":[
{
"name":"Category3",
"y":43,
"x":2
}
]
},
{
"name":"Category4",
"data":[
{
"name":"Category4",
"y":42,
"x":3
}
]
},
{
"name":"Category5",
"data":[
{
"name":"Category5",
"y":42,
"x":4
}
]
},
{
"name":"",
"data":[
{

}
],
"visible":false,
"showInLegend":false,
"exporting":false
},
{
"name":"Bla bla bla",
"data":[
45,
43,
43,
42,
42
],
"showInLegend":false,
"visible":false,
"exporting":true
}
],
"exporting":{
"enabled":false,
"chartOptions":{
"legend":{
"enabled":true,
"maxHeight":null,
"itemStyle":{
"fontFamily":"Arial"
}
}
}
},
"loading":{
"style":{
"opacity":0.9
}
},
"drilldown":{
"drillUpButton":{
"theme":{
"style":{
"display":"none"
}
}
}
}
});

Here is live example .

当我点击第一个或最后一个图例项时,图表正在重绘,但当我点击中间的图例项时没有发生这种情况?这是错误还是功能?我如何才能将中间图例项目的这种行为更改为它们也能够引发重绘图表的事件?

提前致谢

最佳答案

您可以设置和更新 xAxis 的中断以隐藏空白空间:

http://jsfiddle.net/a4vcye4p/1/

  events: {
legendItemClick: function() {
var series = this,
seriesIndex = series._i,
xAxis = series.xAxis,
newBreaks = [];
if (series.visible) {
newBreaks = xAxis.options.breaks;
newBreaks.push({
from: seriesIndex,
to: seriesIndex + 1,
seriesIndex: seriesIndex
});
} else {
Highcharts.each(xAxis.options.breaks, function(br) {
if (br.seriesIndex !== seriesIndex) {
newBreaks.push(br);
}
});
}
xAxis.update({
breaks: newBreaks
});
}
}

关于javascript - 使用highchart在柱形图中隐藏列后如何填充空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39289725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com