当用户想要打印图表时,是否可以更新特定的xAxis标签?
这是初始图表(具有自定义样式的倒置列)。我用格式化程序功能创建了xAxis标签
xAxis: {
arrowOnEnd: true,
labels: {
x: 40,
formatter: function() {
if (this.isLast) { return 'Less Likely' }
if (this.isFirst) { return 'More Likely' }
}
},
并且能够定位它们,因此看起来xAxis的值从极不可能到更可能,如下所示
events: {
load: function() {
// https://stackoverflow.com/questions/51656849/xaxis-point-specific-label-positions
const chart = this;
Highcharts.objectEach(chart.xAxis[0].ticks, function(tick: any) {
if (!tick.isNewLabel && tick.isFirst) { tick.label.attr({ y: 25 })}
if (!tick.isNewLabel && tick.isLast) { tick.label.attr({ y: 590 })}
});
},
我试图在events: { load: ... }
中复制beforePrint
逻辑或将'print'事件包装到highcharts对象,但这似乎没有任何效果 beforePrint: function() {
const chart = this;
Highcharts.objectEach(chart.xAxis[0].ticks, function(tick: any) {
if (tick.isFirst) { tick.label.attr({ y: 125 })}
if (tick.isLast) { tick.label.attr({ y: 590 })}
});
}
Highcharts.wrap(Highcharts.Chart.prototype, 'print', function (proceed) {
const chart = this;
Highcharts.objectEach(chart.xAxis[0].ticks, function(tick: any) {
if (tick.isFirst) { tick.label.attr({ y: 25 })}
if (tick.isLast) { tick.label.attr({ y: 590 })}
});
proceed.call(this)
});
我尝试过tickPositionier
,但实际上无法弄清楚如何使它起作用。值得一提。具有相同逻辑的
afterPrint
事件会重置图表,因此我不明白为什么一个事件在起作用(afterPrint),而另一个事件却不在(print)
afterPrint: function() { const chart = this; Highcharts.objectEach(chart.xAxis[0].ticks, function(tick: any) { if (tick.isFirst) { tick.label.attr({ y: 25 })} if (tick.isLast) { tick.label.attr({ y: 590 })} }); },
我在这里想念什么吗?为什么我不能更新打印的刻度位置?Sidenote-jsfiddle给了我
502 Bad Gateway
,所以我无法在那里演示它
演示:https://jsfiddle.net/BlackLabel/4qbp1w0z/
chart: {
type: 'bar',
events: {
render: function() {
// https://stackoverflow.com/questions/51656849/xaxis-point-specific-label-positions
const chart = this;
Highcharts.objectEach(chart.xAxis[0].ticks, function(tick) {
if (!tick.isNewLabel && tick.isFirst) {
tick.label.attr({
y: 20
})
}
if (!tick.isNewLabel && tick.isLast) {
tick.label.attr({
y: 350
})
}
});
},
}
},
API:https://api.highcharts.com/highcharts/chart.events.render