dreamfly0514 2017-07-06 23:46
浏览 72

Google Chart:“c.getTimezoneOffset不是函数”错误

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 try to render the chart with Date as type string, it renders nicely. But when i try to render the chart with Date as type date/datetime, i get the following error: "c.getTimezoneOffset is not a function"

Here is my code:

PHP array making:

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

Data example:

[[{"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]]

Anybody know what is the problem?

Many thanks!!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程