谷歌图表:" c.getTimezoneOffset不是一个功能"错误

时间:2017-07-06 23:46:34

标签: javascript php jquery charts google-visualization

我试图通过谷歌图表显示货币汇率折线图。

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

  1. 日期(格式iso8601)
  2. 费率(十进制数)
  3. 当我尝试使用Date作为类型字符串呈现图表时,它呈现得很好。 但是当我尝试使用Date作为类型date / datetime呈现图表时,我收到以下错误: " c.getTimezoneOffset不是函数"

    这是我的代码:

    PHP数组制作:

        $arrayForChart =array();
        foreach ($arrayRates as $key => $value) {
            $dateObj= new datetime($value['date']);//$value['date']= date in iso 8601 format: e.g 2017-02-12 
            $dateStringNewDate="new Date(" . $dateObj->format('Y') .",". $dateObj->format('m') . "," . $dateObj->format('d') . ")";//temp for testing
            $dateStringDate="Date(". $value['date'] . ")";//temp for testing
            array_unshift($arrayForChart, array($dateStringDate , $value['rates']["$toCurrency"]));
        }
        array_unshift($arrayForChart, array(array('label'=>'Date','id'=>'Date','type'=>'date'),array('label'=>'Rate','id'=>'Rate','type'=>'number')));
    

    的Javascript

    function dipsplayChart() {
      //from here google chart stuff
      google.charts.load("current", { packages: ["corechart", "line"] });
      google.charts.setOnLoadCallback(drawLineColors);
    
      function drawLineColors() {
        console.log(JSON.stringify(arrayForChart));
        var data = google.visualization.arrayToDataTable(arrayForChart);
    
        var options = {
          title: baseCurrency + " vs " + toCurrency + " Last 90 days",
          explorer: {
            actions: ["dragToZoom", "rightClickToReset"],
            axis: "horizontal",
            keepInBounds: true
          },
          hAxis: {
            title: "Date"
            //type: "date"
          },
          vAxis: {
            title: "Rate"
            //type: "number"
          },
          colors: ["#a52714", "#097138"]
        };
    
        var chart = new google.visualization.LineChart(
          document.getElementById("chart_div")
        );
        chart.draw(data, options);
      }
      //until here google chart stuff
    }
    

    数据示例:

    [[{"label":"Date","id":"Date","type":"date"},{"label":"Rate","id":"Rate","type":"number"}],["new Date(2017,04,10)",3.6618],["new Date(2017,04,11)",3.6565],["new Date(2017,04,12)",3.6551],["new Date(2017,04,13)",3.6539],["new Date(2017,04,18)",3.6652],["new Date(2017,04,19)",3.6655],["new Date(2017,04,20)",3.6651],["new Date(2017,04,21)",3.6798],["new Date(2017,04,24)",3.6523],["new Date(2017,04,25)",3.6443],["new Date(2017,04,26)",3.6365],["new Date(2017,04,27)",3.644],["new Date(2017,04,28)",3.622],["new Date(2017,05,02)",3.6094],["new Date(2017,05,03)",3.6171],["new Date(2017,05,04)",3.6191],["new Date(2017,05,05)",3.6038],["new Date(2017,05,08)",3.6049],["new Date(2017,05,09)",3.6034],["new Date(2017,05,10)",3.6007],["new Date(2017,05,11)",3.6114],["new Date(2017,05,12)",3.6045],["new Date(2017,05,15)",3.597],["new Date(2017,05,16)",3.6056],["new Date(2017,05,17)",3.6017],["new Date(2017,05,18)",3.6045],["new Date(2017,05,19)",3.5859],["new Date(2017,05,22)",3.5817],["new Date(2017,05,23)",3.5871],["new Date(2017,05,24)",3.5897],["new Date(2017,05,25)",3.5769],["new Date(2017,05,26)",3.5734],["new Date(2017,05,29)",3.5724],["new Date(2017,05,30)",3.5517],["new Date(2017,05,31)",3.5431],["new Date(2017,06,01)",3.5511],["new Date(2017,06,02)",3.5605],["new Date(2017,06,05)",3.549],["new Date(2017,06,06)",3.5461],["new Date(2017,06,07)",3.5457],["new Date(2017,06,08)",3.5358],["new Date(2017,06,09)",3.5242],["new Date(2017,06,12)",3.533],["new Date(2017,06,13)",3.5258],["new Date(2017,06,14)",3.5295],["new Date(2017,06,15)",3.5225],["new Date(2017,06,16)",3.5274],["new Date(2017,06,19)",3.5225],["new Date(2017,06,20)",3.5391],["new Date(2017,06,21)",3.5409],["new Date(2017,06,22)",3.5441],["new Date(2017,06,23)",3.5418],["new Date(2017,06,26)",3.531],["new Date(2017,06,27)",3.5168],["new Date(2017,06,28)",3.52],["new Date(2017,06,29)",3.4955],["new Date(2017,06,30)",3.4953],["new Date(2017,07,03)",3.4979],["new Date(2017,07,04)",3.516],["new Date(2017,07,05)",3.5195],["new Date(2017,07,06)",3.5361]]
    

    有人知道这是什么问题吗?

    非常感谢!!

0 个答案:

没有答案