2017-09-01 2 views
0

Ich möchte zwei Diagramme mit CanvasJS erstellen, in denen ich Werte aus PHP-Datei verwenden. Ich habe zwei Diagramme, aber nur eines rendert, das zweite hat nur weißen Hintergrund und Titeltext. Hier PHP-Code mit Werten:CanvasJS und 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"), 
    ); 
?> 

und 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> 

Der gesamte Code ist in index.php Datei.

Für den Rekord, suchte ich andere Lösungen hier sowie auf der offiziellen Seite und keiner arbeitete.

+0

Ich denke ändern, dass das Problem mit 'dataPoints' ist. Es muss in jedem Diagramm "dataPoints" sein, aber wie mache ich das, ohne immer die gleichen Werte zu haben? –

Antwort

0

Lösung ist Datenpunkte Daten haben und es nicht

data: [ 
{ 
type: "column", 
**dataPoints** : <?php echo json_encode($dataP, JSON_NUMERIC_CHECK); ?> 
Verwandte Themen