How do I rotate the legend in Highcharts?

跟風遠走 提交于 2019-12-11 23:29:42

问题


Instead of showing the legend on the bottom under my chart, I want to show it to the left of the y axis, rotated 90 degrees. How do I do that?


回答1:


You can set a custom legend:

$("#a1").click(function() {
    $('.highcharts-legend-item:nth-child(1)').click();
    $(this).toggleClass("leg-clicked");
  });

Use this property in CSS to rotate the legend:

-webkit-transform: rotate(90deg);

Please check the following example:

$(function() {

  $("#a1").click(function() {
    $('.highcharts-legend-item:nth-child(1)').click();
    $(this).toggleClass("leg-clicked");
  });

  $('#container').highcharts({

    series: [{
            name: 'Tokyo',
            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }]
  });
});

Be sure to deactivate Highcharts' legend in CSS:(otherwise, you will get two legends)

.highcharts-legend {
  display: none;
}


来源:https://stackoverflow.com/questions/35998966/how-do-i-rotate-the-legend-in-highcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!