[英]javascript chart data from different php file?
I have a chart.html
that will show some chart and I try to use echo json_encode
to get data from PHP, but the PHP is in different file , How can I define the process.php
in order to let chart.html
get the data ? 我有一个
chart.html
,它将显示一些图表,我尝试使用echo json_encode
从PHP获取数据,但是PHP在不同的文件中,如何定义process.php
以使chart.html
获取数据?
chart.html : chart.html:
<div id="chart_donut" style="height:350px;"></div>
<script>
var chart = echarts.init(document.getElementById('chart_donut'), theme);
trapchart.setOption({
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
calculable: true,
legend: {
x: 'center',
y: 'bottom',
data: <?php echo json_encode($ary, JSON_PRETTY_PRINT);?>
}, ///??????get data from process.php
toolbox: {
show: true,
feature: {
magicType: {
show: true,
type: ['pie', 'funnel'],
option: {
funnel: {
x: '25%',
width: '50%',
funnelAlign: 'center',
max: 1548
}
}
},
restore: {
show: true,
title: "Restore"
},
saveAsImage: {
show: true,
title: "Save Image"
}
}
},
series: [{
name: 'Access to the resource',
type: 'pie',
radius: ['35%', '55%'],
itemStyle: {
normal: {
label: {
show: true
},
labelLine: {
show: true
}
},
emphasis: {
label: {
show: true,
position: 'center',
textStyle: {
fontSize: '14',
fontWeight: 'normal'
}
}
}
},
data: <?php echo json_encode($results, JSON_PRETTY_PRINT);?>
//?????get from process.php
}]
});
</script>
First you need chart.html to be a php file otherwise will not execute php scripts. 首先,您需要chart.html作为php文件,否则将不执行php脚本。
Your process.php should be included at the top of this chart.php ; 您的process.php应该包含在此chart.php的顶部;
process.php should have someting like this process.php应该像这样
//get the data for both arrays
$ary = ..
$results = ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.