0

使用下面的代码显示了我必须做些什么来解决以下问题:

  1. 我需要在栏的顶部显示列值(总是)而不点击它。
  2. 我需要为每个条分配一种颜色
  3. 我需要显示 x 和 Y 标签
  4. 我需要显示最小值 = 0 和最大值为 5,实际上图形显示从 4.3 到 5.0

有任何想法吗?先感谢您。

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        //load the Google Visualization API and the chart
        google.load('visualization', '1', {'packages':['columnchart']});

        //set callback
        google.setOnLoadCallback (createChart);

        //callback function
        function createChart() {

            var data = new google.visualization.DataTable(
                {
                  "cols": [
                        {"id":"","label":"Topping","pattern":"","type":"string"},
                        {"id":"","label":"Promedio","pattern":"","type":"number"}
                      ],
                  "rows": [
                        {"c":[{"v":"1", "f":null},{"v":4.31,"f":null}]},
                        {"c":[{"v":"2", "f":null},{"v":4.84,"f":null}]},
                        {"c":[{"v":"3", "f":null},{"v":4.77,"f":null}]},
                        {"c":[{"v":"4", "f":null},{"v":4.80,"f":null}]},
                        {"c":[{"v":"5", "f":null},{"v":4.78,"f":null}]},
                        {"c":[{"v":"6", "f":null},{"v":4.80,"f":null}]},
                        {"c":[{"v":"7", "f":null},{"v":4.79,"f":null}]},
                        {"c":[{"v":"8", "f":null},{"v":4.83,"f":null}]},
                        {"c":[{"v":"9", "f":null},{"v":4.77,"f":null}]},
                        {"c":[{"v":"10","f":null},{"v":4.85,"f":null}]},
                        {"c":[{"v":"11","f":null},{"v":4.52,"f":null}]}

                      ]
                }
            )

            //instantiate our chart objects
            var chart = new google.visualization.ColumnChart (document.getElementById('chart_div'));

            //define options for visualization
            var options = {

                width: 800,
                height: 300,
                is3D: true,
                legend: 'none',         
                axisTitlesPosition: 'in',
                title: 'My Graphic',

                hAxis: {
                    title: 'hAxis Title', 
                    titleTextStyle: {color: 'red'},
                    textPosition: 'out'
                },

                vAxis: {

                    viewWindowMode: 'explicit', 
                    viewWindow: {
                        max: 5.0,
                        min: 0.0
                    },
                    minValue: 0.0, 
                    maxValue: 5.0, 
                    textPosition: 'out'

                }
            };

            //draw my chart
            chart.draw(data, options);

        }

    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 700px;"></div>
  </body>
</html>

实际图表

4

1 回答 1

0

非常感谢 asgalant。

请转到https://groups.google.com/forum/?fromgroups=#!topic/google-visualization-api/6FyfEBphXO4

于 2012-08-31T16:06:58.957 回答