0

Using this code from google line charts I get the following error all the time:

Uncaught SyntaxError: missing ) after argument list

code:

<script type="text/javascript">
  google.charts.load('current', {packages: ['corechart', 'line']});
  google.charts.setOnLoadCallback(drawLogScales);
  google.charts.setOnLoadCallback(drawLogScalesLTC);

  function drawLogScales() {
        var data = new google.visualization.DataTable();
        data.addColumn('number', 'X');
        data.addColumn('number', 'PTH/s');

        data.addRows([
          [new Date(2016-12-15 21:23:07), 0.78],
          [new Date(2016-12-14 21:23:07), 5.31],
          [new Date(2016-12-13 21:23:07), 8.38],
          [new Date(2016-12-12 21:23:07), 0.72],
          [new Date(2016-12-11 21:23:07), 3.27],
          [new Date(2016-12-10 21:23:07), 0.78],

        ]);

        var options = {
          hAxis: {
            title: 'Time (h)',
            logScale: true
          },
          vAxis: {
            title: 'PTH/s',
            logScale: false
          },
          colors: ['#a52714', '#097138']
        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
</script>

I'm totally baffled where things go wrong. The synatx is fine I think.

wichtel
  • 153
  • 2
  • 16

1 Answers1

0

The problem is actually how you're creating your dates. Since you're passing in a string you should declare a new date with quotes around the date string:

new Date('2016-01-01 01:01:01')

To get your code working I also cast each date to a string and changed the column type for the dates from 'number' to 'string'. See fiddle for working code.

https://jsfiddle.net/nz5yto73/

mrogers
  • 1,072
  • 1
  • 13
  • 21
  • awesome, is there some way to change the format of the date? https://puu.sh/sQODn/8fe51dcff2.png – wichtel Dec 15 '16 at 21:49
  • If you want to stick with pure javascript you could do something like this: http://stackoverflow.com/a/30272803/6913895 – mrogers Dec 15 '16 at 21:58
  • There are also other built in toString functions like toUTCString() or toDateString(). https://msdn.microsoft.com/en-us/library/ff743760(v=vs.94).aspx – mrogers Dec 15 '16 at 21:59