2017-07-04 1 views
1

Ich versuche, ein Liniendiagramm der Währungskurse über google charts anzuzeigen.Google-Diagramm: "Uncaught (in Versprechung) Fehler: Unbekannter Titeltyp: 4.7278" Fehler

Im Grunde habe ich 2 Arten von Werten:

  1. Datum (Format ISO8601)
  2. Rate (Dezimalzahl)

, wenn ich versuche, das Diagramm i einen Fehler zu machen : „Nicht abgefangene (in Versprechen) Fehler: Unbekannter Header-Typ: 4,7278”

Hier ist mein Code:

PHP-Array-Herstellung:

 $xml=simplexml_load_file('https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/usd.xml') or die("Error: Cannot create object"); 
    $arrayForChart[] = ["Date","Rate"]; 
    foreach ($xml->DataSet->Series->Obs as $key => $value) { 
     $dateIso8601Format=(string)$value['TIME_PERIOD']; 
     $rateForDate=(string)$value['OBS_VALUE'][0]; 
     $rateForDate=(float)$rateForDate; 
     $arrayForChart[] = [$dateIso8601Format,$rateForDate]; 
    } 
    $arrayForChart = json_encode($arrayForChart); 

Javascript

var arrayForChart; 
$.ajax({ 
    type: "POST", 
    url: ajaxUrl, 
    //data: {configuration: Config }, 
    success: function (data) { 

     arrayForChart = data; 
     arrayForChart = $.map(arrayForChart, function (el) { 
      return el; 
     });//converting js object to js array 

    }, 
    cache: false 
}); 
google.charts.load("current", {packages: ["corechart", "line"]}); 
google.charts.setOnLoadCallback(drawLineColors); 

function drawLineColors() { 

    var data = google.visualization.arrayToDataTable([arrayForChart]); 

    var options = { 
     hAxis: { 
      title: "Rate", 
      id: "Rate", 
      label: "Rate", 
      type: "number" 
     }, 
     vAxis: { 
      title: "Date", 
      id: "Date", 
      label: "Date", 
      type: "string" 
     }, 
     colors: ["#a52714", "#097138"] 
    }; 

    var chart = new google.visualization.LineChart(document.getElementById("chart_div")); 
    chart.draw(data, options); 
} 

Beispieldaten:

["Date","Rate","2011-01-03",4.7278,"2011-01-04",4.7301,"2011-01-05",4.6814,"2011-01-06",4.6635] 

Wer könnte wissen, was ist das Problem?

Vielen Dank!

+1

Check-out dieses [full Beispiel] (https://stackoverflow.com/a/38955110/5090771) sein ... – WhiteHat

Antwort

2

Google-Diagramme erwartet ein Array von Arrays. Du scheinst es mit einer Wohnung zu versehen. ZB

Array('date', 'value', 1,2,3,4);

Sollte

Array(
    Array(date, value), 
    Array(1, 2), 
    Array(3, 4) 
); 
Verwandte Themen