gpt4 book ai didi

javascript - 渲染后更改 Highcharts 图例显示

转载 作者:行者123 更新时间:2023-11-30 11:51:54 29 4
gpt4 key购买 nike

是否可以在图表呈现后更改 Highcharts 显示设置?还是我总是需要重新绘制图表?

你看,在screen resize上,我想把legend box从右边移到底部,如图: --Example Picture--

以编程方式,我需要的是更改代码

来自:

legend: {        
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
}

到:

legend : {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom',
}

在图表呈现之后。

非常感谢!

最佳答案

解决方法:

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>BBBIndex</title>
@*credit goes to http://stackoverflow.com/questions/33755669/highcharts-change-legend-options-dynamically*@
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
$(function () {

$(document).ready(function () {

// Build the chart
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
},
title: {
text: 'Browser market shares January, 2015 to May, 2015'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [{
name: 'Microsoft Internet Explorer',
y: 56.33
}, {
name: 'Chrome',
y: 24.03,
sliced: true,
selected: true
}, {
name: 'Firefox',
y: 10.38
}, {
name: 'Safari',
y: 4.77
}, {
name: 'Opera',
y: 0.91
}, {
name: 'Proprietary or Undetectable',
y: 0.2
}]
}]
});
});

$("#btnProgChgLegend").toggle(
function () {
var c = $('#container').highcharts();
var o = c.options;
o.legend.layout = "vertical";
o.legend.align = "right";
o.legend.verticalAlign = "top";
//next line is key
c.legend.render();
},
function () {
var c = $('#container').highcharts();
var o = c.options;
o.legend.layout = "horizontal";
o.legend.align = "center";
o.legend.verticalAlign = "bottom";
c.legend.render();
});
});
</script>
</head>
<body>
<div>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
<button type="button" id="btnProgChgLegend">Change Legend Programmatically</button>
</div>
</body>
</html>

关于javascript - 渲染后更改 Highcharts 图例显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39211593/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com