我正在尝试使用JavaScript绘制饼图,这里的挑战是我不知道图表将有多少切片,所以我必须读取数据库中的图表值。那么,我如何将PHP代码放在值:[10,12,78,15,45,55],中以获取实时值?
<script type="text/javascript">
var data = [{
values: [10,12,78,15,45, 55],
labels: ['OK', 'NO','MAYBE', 'SOMETIMES','NEVER', 'I DONT KNOW'],
type: 'pie'
}];
var layout = {
height: 380,
width: 480
};
Plotly.newPlot(graph, data, layout);
</script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<!-- Numeric JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js"> //Hosted Scripts
<div id="graph" style="width: 480px; height: 380px;"> </div>