[英]Highchart (pie chart) with data from HTML table not displaying legend
I have a highchart (pie chart) which is loading its data from a dynamic HTML table. 我有一个highchart(饼图),它是从动态HTML表加载其数据的。 The chart itself is working well, but, I can't get the legend to show up.
图表本身运行良好,但是我无法显示图例。
Has anyone else had this problem where the legend for a chart won't appear? 还有其他人遇到过这样的问题,即图表的图例不会出现吗? And, do you know of a solution?
而且,您知道解决方案吗?
I've looked at the examples on the Highcharts website and can't seem to find a solution. 我查看了Highcharts网站上的示例,但似乎找不到解决方案。
The container: 容器:
<section>
<div style="float:left;margin-right:10px;">
<div id="container" style="min-width: 250px; max-width: 250px; height: 500px; margin: 0 auto"></div>
</div>
...
</section>
The chart JS: 图表JS:
// Create the chart
$(function () {
$('#container').highcharts({
data: {
table: document.getElementById('datatable')
},
chart: {
type: 'pie',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
legend: {
align: 'center',
verticalAlign:'top'
},
title: {
text: 'Subject Breakdown'
},
tooltip: {
pointFormat: '{point.name}: <b>{point.y}</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y;
},
showInLegend: true
}
}
}
});
});
The table: 桌子:
<!-- Data for Subject Breakdown Chart -->
<table id="datatable">
<thead>
<tr>
<th>name</th>
<th>name</th>
</tr>
</thead>
<tbody>
<?php
$count=1;
$sel_query="Select subject, count(subject) as total from engagements GROUP BY subject;";
$result = mysqli_query($con,$sel_query);
while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<th><?php echo $row['subject']; ?><th>
<td><?php echo $row['total']; ?></td>
</tr>
<?php $count++; } ?>
</tbody>
</table>
It occurs because you placed the showInLegend
inside of the dataLabels
configuration object, instead of pie
. 发生这种情况是因为您将
showInLegend
放置在dataLabels
配置对象中,而不是pie
。 Please just cut/paste it directly to plotOptions.pie
object, and everything will works as you expecting. 请直接将其剪切/粘贴到
plotOptions.pie
对象,一切都会按预期进行。
data: {
table: document.getElementById('datatable')
},
chart: {
type: 'pie',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
legend: {
//align: 'center',
//verticalAlign: 'top'
},
title: {
text: 'Subject Breakdown'
},
tooltip: {
pointFormat: '{point.name}: <b>{point.y}</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>' + this.point.name + '</b>: ' + this.y;
},
},
showInLegend: true
}
}
Live example: http://jsfiddle.net/qw5y4nvm/ 实时示例: http : //jsfiddle.net/qw5y4nvm/
API Reference: https://api.highcharts.com/highcharts/plotOptions.pie.showInLegend API参考: https : //api.highcharts.com/highcharts/plotOptions.pie.showInLegend
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.