谷歌图表:“未捕获(承诺)错误:未知的标题类型:4.7278”错误 [英] Google chart: “Uncaught (in promise) Error: Unknown header type: 4.7278” error

查看:144
本文介绍了谷歌图表:“未捕获(承诺)错误:未知的标题类型:4.7278”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



基本上我有两种类型的值:
$ b $ ol
  • 日期(格式为iso8601)

  • 费率(十进制数)

  • 当我尝试渲染图表时,

    这是我的代码:



    PHP数组制作:

    $ $ $ $ $ xml = simplexml_load_file );
    $ 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; $ b $ 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;
    }); //转换js对象到js数组

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

    函数drawLineColors(){

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

    var options = {
    hAxis:{
    title:Rate,
    id:Rate,
    label:Rate,
    类型:数字
    },
    vAxis:{
    标题:日期,
    id:日期,
    标签:日期 ,
    类型:字符串
    },
    颜色:[#a52714,#097138]
    };

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

    $ / code>

    数据示例:

      [ 日期, 速率, 2011-01-03,4.7278 2011-01-04,4.7301 2011-01-05,4.6814 ,2011-01-06,4.6635] 

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

    非常感谢!

    解决方案

    Google图表需要一个数组数组。你似乎正在提供一个平面。例如



    数组('date','value',1,2,3,4);

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


    I'm trying to display a line chart of currency rates via google charts.

    Basically i have 2 type of values:

    1. Date (format iso8601)
    2. Rate (decimal number)

    when i'm trying to render the chart i get an error: "Uncaught (in promise) Error: Unknown header type: 4.7278"

    Here is my code:

    PHP array making:

            $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);
    }
    

    Sample of data:

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

    Anybody might know what is the problem?

    Many thanks!

    解决方案

    Google charts expects an array of arrays. You appear to be providing it with one flat away. Eg

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

    Should be

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

    这篇关于谷歌图表:“未捕获(承诺)错误:未知的标题类型:4.7278”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆