Liv*_*eEn 2 ajax jquery highcharts
我正在使用Highcharts,我想在一个页面上添加多个图表
下面是我的js代码
<script type="text/javascript">
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Visual Data'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Market Share',
data: [
['Plan 1', <?php echo $1; ?>],
['Plan 2', <?php echo $2; ?>],
['Plan 3', <?php echo $3; ?>]
]
}]
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我可以简单地重复代码并更改代码renderTo:'container'来显示其他图表,但代码重复多次.
有没有更好的方法,我可以重用代码,以便我可以传递数据
series: []
title: {
text: 'Visual Data'
},
Run Code Online (Sandbox Code Playgroud)
显示多个图表.目前我想在一个页面中显示5个图表.
您可以使用它Highcharts.setOptions来定义页面上所有图表相同的选项.以下是示例代码:
Highcharts.setOptions({
global: {
//Highchart uses UTC time by default
useUTC: false
},
legend: {
enabled: false
},
credits: {
enabled: false
},
xAxis: {
type: 'datetime',
tickColor: '#96AA8C',
labels: {
style: {
color: '#555F50'
}
},
tickPixelInterval: 70,
maxZoom: 20 * 1000
},
title: {
style: {
color: '#343434'
}
},
tooltip: {
xDateFormat: '%d/%m/%Y %H:%M:%S'
}
});
Run Code Online (Sandbox Code Playgroud)
您可以通过这种方式定义所有属性(不确定"全部").
| 归档时间: |
|
| 查看次数: |
5050 次 |
| 最近记录: |