|
|
1
ewolden
6 年前
实现你的目标
2014
结果,您可以使用
highchart wrapper
,并更改点的绘制方式,如下所示:
(function (H) {
H.wrap(H.seriesTypes.column.prototype, 'drawPoints', function (proceed) {
$.each(this.points, function (i,point) {
let borderRadius = this.options.borderRadius;
point.shapeArgs.y -= borderRadius;
point.shapeArgs.height += borderRadius;
});
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
(function (H) {
H.wrap(H.seriesTypes.column.prototype, 'drawPoints', function (proceed) {
let seriesIndex = this.index
$.each(this.points, function (i,point) {
point.shapeArgs.y -= seriesIndex == 0 ? 0 : 5;
point.shapeArgs.height += 5;
});
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
Highcharts.chart('container', {
chart: {
type: 'column',
spacingBottom: 0
},
title: {
text: ''
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'],
offset: 7,
lineWidth: 0,
tickLength: 0
},
yAxis: {
min: 0,
title: {
text: ''
},
stackLabels: {
enabled: false,
style: {
fontWeight: 'bold',
color: 'gray'
}
},
visible: false
},
legend: {
align: 'center',
verticalAlign: 'bottom',
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
series: {
},
column: {
stacking: 'normal',
borderWidth: 0,
borderRadius: 5,
dataLabels: {
enabled: true,
color: 'white'
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2],
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
https://jsfiddle.net/ewolden/cyfv64ub/122/
如果你想要
结果相反,使用相同的函数,如下所示:
(function(H) {
H.wrap(H.seriesTypes.column.prototype, 'drawPoints', function(proceed) {
let seriesIndex = this.index,
firstIndex = this.chart.series[0].index,
lastIndex = this.chart.series[this.chart.series.length - 1].index,
borderRadius = this.options.borderRadius;
this.options.borderRadius = 0;
$.each(this.points, function(i, point) {
if (seriesIndex != firstIndex && seriesIndex != lastIndex) {
point.shapeArgs.y -= borderRadius;
point.shapeArgs.height += borderRadius*2;
}
});
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
$.each(this.points, function(i, point) {
if (seriesIndex == firstIndex || seriesIndex == lastIndex) {
point.graphic.attr({
r: borderRadius
});
}
});
});
}(Highcharts));
我手动设置系列的zIndex,但也可以这样做。只是现在没时间找地方放。
(function(H) {
H.wrap(H.seriesTypes.column.prototype, 'drawPoints', function(proceed) {
let seriesIndex = this.index,
firstIndex = this.chart.series[0].index,
lastIndex = this.chart.series[this.chart.series.length - 1].index,
borderRadius = this.options.borderRadius;
this.options.borderRadius = 0;
$.each(this.points, function(i, point) {
if (seriesIndex != firstIndex && seriesIndex != lastIndex) {
point.shapeArgs.y -= borderRadius;
point.shapeArgs.height += borderRadius*2;
}
});
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
$.each(this.points, function(i, point) {
if (seriesIndex == firstIndex || seriesIndex == lastIndex) {
point.graphic.attr({
r: borderRadius
});
}
});
});
}(Highcharts));
Highcharts.chart('container', {
chart: {
type: 'column',
spacingBottom: 0
},
title: {
text: ''
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas'],
offset: 7,
lineWidth: 0,
tickLength: 0
},
yAxis: {
min: 0,
title: {
text: ''
},
stackLabels: {
enabled: false,
style: {
fontWeight: 'bold',
color: 'gray'
}
},
visible: false
},
legend: {
align: 'center',
verticalAlign: 'bottom',
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
series: {
},
column: {
stacking: 'normal',
borderWidth: 0,
borderRadius: 5,
dataLabels: {
enabled: true,
color: 'white'
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2],
zIndex: 0
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1],
zIndex: 1
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5],
zIndex: 0
}]
});
<脚本src=“https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js“></script>
<脚本src=“https://code.highcharts.com/highcharts.js“></script>
<脚本src=“https://code.highcharts.com/modules/exporting.js“></script>
<脚本src=“https://code.highcharts.com/modules/export-data.js“></script>
<div id=“container”style=“最小宽度:310px;高度:400px;边距:0自动”></div>
工作中间:
https://jsfiddle.net/ewolden/kqrLs3m8/
drawPoints
在这里,正如docs所述,它只在开始时运行一次。因此,如果您开始禁用/启用序列,那么它们就不一定像您期望的那样。
|