谷歌图表:"轴#0的数据列不能是字符串" eror

时间:2017-07-04 15:48:46

标签: javascript php jquery charts google-visualization

我试图通过google charts显示货币汇率折线图。

基本上我有两种类型的值:

  1. 日期(格式iso8601)
  2. 费率(十进制数)
  3. 当我试图渲染图表时,我得到一个错误:"轴#0的数据列不能是字符串"

    这是我的代码:

    PHP数组制作:

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

    数据样本:

    ["Rate","4.7278","4.7301","4.6814"]
    

    任何人都可能知道这是什么问题?

    非常感谢!

0 个答案:

没有答案