1

Google チャートに問題があります。私はGoogleエリアチャートを持っています:

<script type="text/javascript">
  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = new google.visualization.DataTable();
     data.addColumn('timeofday','time');
     data.addColumn('number','temp');
     data.addRows([
       [[8,0,0],7.875],
       [[8,15,0],7.9399996],
       [[8,30,0],8.1],
       [[8,45,0],8.160001],
       [[9,0,0],8.139999],
       // data every quarter of an hour
       [[7,15,0],9.26],
       [[7,30,0],9.26],
       [[7,45,0],9.18]
     ]);

    var options = {
      title: 'Title',
      vAxis: {
        title: 'AvgTemp',
        titleTextStyle: {color: 'red'},
      }
      hAxis: {
        title: 'Time',
        titleTextStyle: {color: 'red'},
      }
    };

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

ここで、ページを読み込むと、グラフの hAxis が 0:00 から 24:00 に始まり、グラフが破棄されます。チャートが 8:00 に開始し、7:45 に終了するようにするにはどうすればよいですか?

ビューウィンドウでいくつか試してみましたが、うまくいかないようです。

ありがとう。

4

2 に答える 2

1

The answer was to use a datetime instead of a time of the day, this way you need to add a date and thats how the api knows which time comes first.

like this:

<script type="text/javascript">
  google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = new google.visualization.DataTable();
     data.addColumn('datetime','time');
     data.addColumn('number','temp');
     data.addRows([

    [new Date(2012,11,3,8,0,0),7.875],
    [new Date(2012,11,3,8,15,0),7.9399996],
    [new Date(2012,11,3,8,30,0),8.1],
    [new Date(2012,11,3,8,45,0),8.160001],
    [new Date(2012,11,3,9,0,0),8.139999],
    //new data every quarter of an hour
    [new Date(2012,11,4,7,0,0),9.42],
    [new Date(2012,11,4,7,15,0),9.26],
    [new Date(2012,11,4,7,30,0),9.26],
    [new Date(2012,11,4,7,45,0),9.18]

     ]);

    var options = {
      title: 'Title',
      vAxis: {  title: 'AvgTemp',
                titleTextStyle: {color: 'red'},

            },
      hAxis: {  title: 'Time',
                titleTextStyle: {color: 'red'},                 
            }

    };

    var chart = new google.visualization.AreaChart(document.getElementById('chart_div2'));
    chart.draw(data, options);
  }
</script>
于 2012-11-04T18:48:47.127 に答える