Google图表-如何将注释居中

时间:2019-10-15 00:25:46

标签: javascript google-visualization column-chart

我一直在玩Google图表。我有一列堆积的酒吧。我想将注释集中到列中。这是我的代码。尽我所能,我无法弄清楚。我发现了一个被描述为黑客的代码块,但必须为每个图表自定义代码块。我使用此代码生成大量图表。任何帮助将不胜感激!

<script type = "text/javascript" src = "https://www.gstatic.com/charts/loader.js">
          </script>
          <script type = "text/javascript">
             google.charts.load('current', {packages: ['corechart']});     
          </script>


          <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto">
          </div>
          <script language = "JavaScript">
             function drawChart() {
                var data = google.visualization.arrayToDataTable([
            ['Genre', 'Fantasy & Sci Fi', { role: 'annotation' }, 'Romance', { role: 'annotation' }, 'Mystery/Crime', { role: 'annotation' }, 'General', { role: 'annotation' },
             'Western', { role: 'annotation' }, 'Literature', { role: 'annotation' } ],
            ['2010', 10, 'a' , 24, 'a', 20, 'a', 32, 'a', 18, 'a', 5, 'a', ],
            ['2020', 16,  'a', 22, 'a', 23, 'a', 30, 'a', 16, 'a', 9, 'a', ],
            ['2030', 28, 'a', 19, 'a', 29, 'a', 30, 'a', 12, 'a', 13, 'a', ]
          ]);



                var options = {
                                title: "h",
                                width: 600,

                                legend: { position: "none" },
                                isStacked:true
                            };

                var chart = new google.visualization.BarChart(document.getElementById('container'));
                chart.draw(data, options);
          google.visualization.events.addListener(chart, 'select', selectHandler);
          function selectHandler(e) {
              var selection = chart.getSelection();
              if (selection.length == true && selection[0].row != null) {
              console.log(selection[0])
                 //alert('You selected ' +data.getValue(selection[0].row, selection[0].column));
                 //window.open(data.getValue(selection[0].row, 0));
                  window.open('https://www.google.com/search?q='+data.getValue(selection[0].row, selection[0].column));
               } 
            }
             }
             google.charts.setOnLoadCallback(drawChart);
          </script>

0 个答案:

没有答案