1

我需要使用基于 1 周、2 个月、4 个月、8 个月和 12 个月的产品的平均评分来可视化谷歌图表,所以我尝试使用谷歌可视化工具将其可视化,所以我得到了下面的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>
      Google Visualization API Sample
    </title>
    <script type="text/javascript" src="//www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['corechart']});
    </script>
    <script type="text/javascript">
      function drawVisualization() {
        // Create and populate the data table.
        var data = google.visualization.arrayToDataTable([
          ['Duration', 'rating'],
          ['1 week',  1],
          ['2 Months',  2],
          ['4 Months',  3],
          ['8 Months',  4],
          ['1 Year',  5],

        ]);

        // Create and draw the visualization.
        new google.visualization.ColumnChart(document.getElementById('visualization')).
            draw(data,
                 {title:"Yearly Coffee Consumption by Country",
                  width:600, height:400,
                  hAxis: {title: "Year"}}
            );
      }


      google.setOnLoadCallback(drawVisualization);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="visualization" style="width: 600px; height: 400px;"></div>
  </body>
</html>

在这里它将输出显示为在此处输入图像描述

​ 我需要 y 轴必须是 1 到 5,并且 x 轴必须具有基于时间范围的平均评分,这可能吗?我必须做什么?

4

1 回答 1

1

要回答问题的第一部分...

...y 轴必须是 1 到 5...

...您必须格式化 y 轴,这还没有在您的代码中。

将您的呼叫更改google.visualization.ColumnChart

new google.visualization.ColumnChart(
    document.getElementById('visualization')).draw(
        data, {
            title:  "Yearly Coffee Consumption by Country",
            width:  600,         
            height: 400,
            hAxis: {
                title: "Year"
            },
        vAxis: {                  <- new code from here...
            minValue:0, 
            format:'#',
            gridlines:{
                count:6
            }
        }
    }
);

这应该根据您的描述格式化轴。

你问题的第二部分,

... x 轴必须具有基于时间范围的平均评级...

我还不清楚。请向其中添加更多细节,例如您想要在哪里/如何/什么样的数据。

于 2013-10-14T06:04:56.607 回答