Google图表的平均评分

时间:2013-10-14 05:50:07

标签: charts datatable

我需要使用基于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>

此处显示输出为enter image description here

我需要y轴必须是1到5,而x轴必须具有基于时间范围的平均等级,这是可能的吗?我该怎么办?

1 个答案:

答案 0 :(得分: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
            }
        }
    }
);

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

问题的第2部分,

  

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

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

相关问题