我做到這一點使用asp.net(MVC5),但我認爲是PHP一樣的想法,希望它幫助。
<script>
$(function() {
var chart = new Highcharts.Chart({
chart: {
type: 'column',
renderTo: 'container'
},
title: {
text: "Client's downloads"
},
subtitle: {
text: 'Click the columns to view products.'
},
xAxis: {
type: 'category'
},
yAxis: {
title: {
text: 'Total downloads'
}
},
legend: {
enabled: false
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true
}
}
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}</b><br/>'
},
series: [{
name: "Downloads",
colorByPoint: true,
data: [
@foreach (var item in Model)
{
<text>{</text>
<text>name: "</text> @item.Name <text>",</text>
<text>y: </text> @item.Downloads <text>,</text>
<text>drilldown: "</text>@item.Name<text>"},</text>
}
]
}],
drilldown: {
series: [
@foreach (var item in Model)
{
<text>{</text>
<text>name: "</text>@item.Name<text>",</text>
<text>id: "</text>@item.Name<text>",</text>
<text>data: [</text>
foreach (var download in item.ProductDownloads)
{
<text>["</text> @download.Product <text>", </text> @download.Downloads <text>],</text>
}
<text>]</text>
<text>},</text>
}
]
}
});
});
</script>
我的建議是使用只是JavaScript代碼,然後當它工作添加您的PHP代碼。 –
謝謝你,這有助於理解如何去做的邏輯概念 –