2017-09-01 12 views
0

私はCanvasJSでphpファイルの値を使用する2つのチャートを作成したいと思います。 私は2つのチャートを持っていますが、レンダリングは1つしかありません。第2のチャートは白い背景とタイトルテキストしかありません。 は、ここで値を持つPHPコードです:CanvasJSとPHP

<?php 
require 'excCon.php'; 
$dataPoints = array(
    array("y" => $excel_result, "label" => "Quantity"), 
    array("y" => $excel_result2, "label" => "Value"), 
    ); 

$dataP = array(
    array("y" => $excel_result3, "name" => "1", "exploded" => false), 
    array("y" => $excel_result4, "name" => "2"), 
    array("y" => $excel_result5, "name" => "3&5"), 
    array("y" => $excel_result6, "name" => "4"), 
    ); 
?> 

とJavaScript:

<div id="chartContainer style="height: 400px;width: 80%""> 
       <script type="text/javascript"> 
        $(function() { 
         var chart1 = new CanvasJS.Chart("chartContainer", { 
          theme: "theme2", 
          animationEnabled: true, 
          title: { 
           text: "Sum" 
          }, 
          data: [ 
           { 
            type: "column", 
            dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?> 
           } 
         ] 
         }); 
         chart1.render(); 
        }); 
       </script> 
      </div> 
      <div id="chartContainer2" style="height: 400px;width: 80%"> 
       <script type="text/javascript"> 
        $(function() { 
         var chart2 = new CanvasJS.Chart("chartContainer2", 
          { 
           theme: "theme2", 
           title:{ 
            text: "All" 
           }, 
           exportFileName: "All", 
           exportEnabled: false, 
           animationEnabled: false, 
           data: [ 
            { 
             type: "pie", 
             showInLegend: true, 
             toolTipContent: "{name}: <strong>{y}%</strong>", 
             indexLabel: "{name} {y}%", 
             dataP: <?php echo json_encode($dataP, JSON_NUMERIC_CHECK); ?> 
            }] 
          }); 
         chart2.render(); 
        }); 
       </script> 
      </div> 

全体のコードがindex.phpファイルです。

ここでは、公式ページだけでなく、他のソリューションも検索しましたが、いずれも機能しませんでした。

+0

私は問題がdataPoints' 'であると考えて変わらないです。それはすべてのチャートで 'dataPoints'でなければなりませんが、毎回同じ値を持たずにどうすればいいですか? –

答えて

0

ソリューションは、データ内のdataPointsのを持っているし、それが

data: [ 
{ 
type: "column", 
**dataPoints** : <?php echo json_encode($dataP, JSON_NUMERIC_CHECK); ?> 
関連する問題