Google Chart - Как разместить аннотацию по центру - PullRequest
1 голос
/ 15 октября 2019

Я играл с гугл чартом. У меня есть столбец с накоплением бар. Я хочу, чтобы аннотация центрировалась в колонке. Это мой кодПопробуйте, как я мог, я не могу понять это. Я нашел блок кода, который был описан как хакерский, но он должен быть настроен для каждого графика. Я использую этот код для генерации множества графиков. Любая помощь будет очень полезна!

<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>
...