簡體   English   中英

Google圖表:如何在色軸上添加標題

[英]Google Charts: How to add a caption to the color axis

向氣泡圖色軸添加標題

在一個項目中,我將使用Google Chart API來顯示帶有三個變量的氣泡圖。 我知道如何更改軸的標題,但是如何向圖表頂部的顏色欄添加標題?

一個例子

我從文檔中修改了示例,以包括軸標簽。 請不要在原件上沒有綠色標題“如何向該欄添加標題”。

我想在圖表頂部以綠色字母添加標題

這是Google文檔的原始源代碼,我在其中添加了軸的title屬性。 我試圖將title屬性添加到colorAxis,但是沒有任何效果。

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['ID', 'X', 'Y', 'Temperature'],
          ['',   80,  167,      120],
          ['',   79,  136,      130],
          ['',   78,  184,      50],
          ['',   72,  278,      230],
          ['',   81,  200,      210],
          ['',   72,  170,      100],
          ['',   68,  477,      80]
        ]);

        var options = {
          colorAxis: {colors: ['yellow', 'red']},
          hAxis: { title: "X AXIS" },
          vAxis: { title: "Y AXIS" }

        };

        var chart = new google.visualization.BubbleChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>
  </body>
</html>

我的問題

如何添加與上圖類似的標題?

您可以為圖表添加標題,該標題將位於colorAxis正上方:

var options = {
    title: 'How can I add a caption to this bar?',
    colorAxis: {colors: ['yellow', 'red']},
    hAxis: { title: "X AXIS" },
    vAxis: { title: "Y AXIS" }
};

它不完全是colorAxis的標題,但是可以具有相同的效果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM