答案 0 :(得分:1)
使用ajax从数据库加载数据并调用图表函数。
$("#btn").click(function(){ //function called on button click.
$.ajax({
url: "dataURL",
success: function(result){
//result should be a array of json and the format of data should be similar to what Highcharts uses.
drawChart(result); //calling highcharts function to draw chart.
}
});
});
function drawChart(data)
{
$('#container').highcharts({ //html body should have div with id container.
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: data //this is where you pass the data to create the chart.
});
}
}
我做了一个小提琴示例来展示这一点,但由于我无法动态加载数据,因此我创建了一个局部变量json,并且只需点击一个按钮即可创建图表。