2016-06-26 4 views
2

私はchart.htmlを持っていますが、私はecho json_encodeを使用してPHPからデータを取得しようとしますが、PHPは別のファイルにあります。chart.htmlにデータを取得させるにはどうすればprocess.phpを定義できますか?別のPHPファイルからのjavascriptのグラフのデータですか?

は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> 
+0

てみ ' 'process.php' を含めるようにいろいろ書いていなければなりません;' –

答えて

0

まず、chart.htmlがそうでなければPHPスクリプトを実行しませんPHPファイルである必要があります。

あなたのprocess.phpはこのchart.phpの上部に含まれています ;

process.phpこの

//get the data for both arrays 
$ary = .. 
$results = ... 
関連する問題