如何在Highcharts JS中为多列图表显示沿Y轴的X轴虚线标签。

huangapple go评论97阅读模式
英文:

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

如何在Highcharts JS中为多列图表显示沿Y轴的X轴虚线标签。

答案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

huangapple
  • 本文由 发表于 2023年6月1日 14:58:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379388.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定