简体   繁体   中英

How do I rotate the legend in Highcharts?

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?

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM