英文:
How to show x-axis dotted labels on y-axis for multiple column chart in hightchart js
问题
可以使用Highcharts在多列图表上显示x轴标签名称为“年度销售”(year to date sales),并将y轴标签设置为“销售OKR”(OKR for sales)。以下是您提供的脚本的翻译:
chart = Highcharts.chart('chart-container_' + nextChartId, {
chart: {
spacingTop: 3,
spacingRight: 0,
spacingBottom: 3,
spacingLeft: 0,
type: chartType,
inverted: hasSwitchChart
},
title: {
text: resData.name,
},
yAxis: {
title: {
text: yAxisName
},
},
xAxis: {
categories: chartData,
type: 'datetime',
// reversed: true
title: {
text: xAxisName
},
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: hasShowDataValue,
format: '{point.y}'
}
}
},
series: chartSeriesData
});
请查看附件!
示例链接:https://jsfiddle.net/js2t3hn9/3/
请指导我。
谢谢!
英文:
Can we show x-axis label names year to date sales and OKR for sales on y-axis for multiple column chart using highchart.
I am using this script
chart = Highcharts.chart('chart-container_'+nextChartId, {
chart: {
spacingTop: 3,
spacingRight: 0,
spacingBottom: 3,
spacingLeft: 0,
type: chartType,
inverted: hasSwitchChart
},
title: {
text: resData.name,
},
yAxis: {
title: {
text: yAxisName
},
},
xAxis: {
categories: chartData,
type: 'datetime',
//reversed: true
title: {
text: xAxisName
},
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: hasShowDataValue,
format: '{point.y}'
}
}
},
series: chartSeriesData
});
Please see attachment!
Example: https://jsfiddle.net/js2t3hn9/3/
Please guide me.
Thanks
答案1
得分: 1
我看到你想要将图例项目放在y轴标题的位置。要做到这一点,你可以在render
事件中旋转和动态定位图例,例如:
Highcharts.chart('container', {
chart: {
...,
events: {
render: function() {
const chart = this;
chart.legend.group.attr({
rotation: -90,
translateX: 0,
translateY: chart.yAxis[0].height / 2 + chart.legend.legendWidth / 2 + chart.plotTop
});
}
}
},
legend: {
enabled: true,
align: 'left',
verticalAlign: 'middle',
floating: true
},
...
});
Live demo: 示例链接
API参考文档: API 参考文档
英文:
I see that you want to place legend items in place of the y-axis title. To do that, you can rotate and dynamically position the legend, for example in render
event.
Highcharts.chart('container', {
chart: {
...,
events: {
render: function() {
const chart = this;
chart.legend.group.attr({
rotation: -90,
translateX: 0,
translateY: chart.yAxis[0].height / 2 + chart.legend.legendWidth / 2 + chart.plotTop
});
}
}
},
legend: {
enabled: true,
align: 'left',
verticalAlign: 'middle',
floating: true
},
...
});
Live demo: http://jsfiddle.net/BlackLabel/fwmoyjxs/
API Reference: https://api.highcharts.com/class-reference/Highcharts.SVGElement#attr
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论