Google折线图中hAxis标题文本位置

huangapple go评论67阅读模式
英文:

hAxis title text position in Google line chart

问题

以下是要翻译的内容:

"An example is here: https://jsfiddle.net/beo4qjsg/1/

It's essentially the same code used for "Multiple line types" example in Google Charts documentation, with one change. Specifically, I have the following in options:

var options = {
	width: 1000, height: 850, 
	chartArea: {left:75, top:75, height:450, width:550},
	hAxis: {
		title: 'Time'
	},
	vAxis: {
		title: 'Popularity'
	},
	series: {
		1: {curveType: 'function'}
	}
};

The output image looks like this:
Google折线图中hAxis标题文本位置

As can be seen here, the title for X-axis "Time" is quite far from the axis itself. Is there any way to bring it closer? It is important that I keep the chartArea.height set to a specific value, so that's something I cannot change.

英文:

An example is here: https://jsfiddle.net/beo4qjsg/1/

It's essentially the same code used for "Multiple line types" example in Google Charts documentation, with one change. Specifically, I have the following in options:

      var options = {
      	width: 1000, height: 850, 
        chartArea: {left:75, top:75, height:450, width:550},
        hAxis: {
          title: 'Time'
        },
        vAxis: {
          title: 'Popularity'
        },
        series: {
          1: {curveType: 'function'}
        }
      };

The output image looks like this:
Google折线图中hAxis标题文本位置

As can be seen here, the title for X-axis "Time" is quite far from the axis itself. Is there any way to bring it closer? It is important that I keep the chartArea.height set to a specific value, so that's something I cannot change.

答案1

得分: 1

chartArea选项中,添加一个bottom选项

chartArea: {left:75, top:75, width:550, bottom: 40, height: '100%'},

查看以下的工作示例...

<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
google.charts.load('current', {
  packages: ['corechart', 'line']
}).then(function() {
  var data = new google.visualization.DataTable();
  data.addColumn('number', 'X');
  data.addColumn('number', 'Dogs');
  data.addColumn('number', 'Cats');

  data.addRows([
    [0, 0, 0],    [1, 10, 5],   [2, 23, 15],  [3, 17, 9],   [4, 18, 10],  [5, 9, 5],
    [6, 11, 3],   [7, 27, 19],  [8, 33, 25],  [9, 40, 32],  [10, 32, 24], [11, 35, 27],
    [12, 30, 22], [13, 40, 32], [14, 42, 34], [15, 47, 39], [16, 44, 36], [17, 48, 40],
    [18, 52, 44], [19, 54, 46], [20, 42, 34], [21, 55, 47], [22, 56, 48], [23, 57, 49],
    [24, 60, 52], [25, 50, 42], [26, 52, 44], [27, 51, 43], [28, 49, 41], [29, 53, 45],
    [30, 55, 47], [31, 60, 52], [32, 61, 53], [33, 59, 51], [34, 62, 54], [35, 65, 57],
    [36, 62, 54], [37, 58, 50], [38, 55, 47], [39, 61, 53], [40, 64, 56], [41, 65, 57],
    [42, 63, 55], [43, 66, 58], [44, 67, 59], [45, 69, 61], [46, 69, 61], [47, 70, 62],
    [48, 72, 64], [49, 68, 60], [50, 66, 58], [51, 65, 57], [52, 67, 59], [53, 70, 62],
    [54, 71, 63], [55, 72, 64], [56, 73, 65], [57, 75, 67], [58, 70, 62], [59, 68, 60],
    [60, 64, 56], [61, 60, 52], [62, 65, 57], [63, 67, 59], [64, 68, 60], [65, 69, 61],
    [66, 70, 62], [67, 72, 64], [68, 75, 67], [69, 80, 72]
  ]);

  var options = {
    width: 1000, height: 850, 
    chartArea: {left:75, top:75, width:550, bottom: 40, height: '100%'},
    hAxis: {
      title: 'Time'
    },
    vAxis: {
      title: 'Popularity'
    },
    series: {
      1: {curveType: 'function'}
    }
  };

  var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
  chart.draw(data, options);
});
<!-- language: lang-html -->
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
<!-- end snippet -->

如果你有其他问题或需要进一步的翻译,请告诉我。

英文:

in the option for chartArea, add an option for bottom

    chartArea: {left:75, top:75, width:550, bottom: 40, height: &#39;100%&#39;},

see following working snippet...

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

google.charts.load(&#39;current&#39;, {
  packages: [&#39;corechart&#39;, &#39;line&#39;]
}).then(function() {
  var data = new google.visualization.DataTable();
  data.addColumn(&#39;number&#39;, &#39;X&#39;);
  data.addColumn(&#39;number&#39;, &#39;Dogs&#39;);
  data.addColumn(&#39;number&#39;, &#39;Cats&#39;);

  data.addRows([
    [0, 0, 0],    [1, 10, 5],   [2, 23, 15],  [3, 17, 9],   [4, 18, 10],  [5, 9, 5],
    [6, 11, 3],   [7, 27, 19],  [8, 33, 25],  [9, 40, 32],  [10, 32, 24], [11, 35, 27],
    [12, 30, 22], [13, 40, 32], [14, 42, 34], [15, 47, 39], [16, 44, 36], [17, 48, 40],
    [18, 52, 44], [19, 54, 46], [20, 42, 34], [21, 55, 47], [22, 56, 48], [23, 57, 49],
    [24, 60, 52], [25, 50, 42], [26, 52, 44], [27, 51, 43], [28, 49, 41], [29, 53, 45],
    [30, 55, 47], [31, 60, 52], [32, 61, 53], [33, 59, 51], [34, 62, 54], [35, 65, 57],
    [36, 62, 54], [37, 58, 50], [38, 55, 47], [39, 61, 53], [40, 64, 56], [41, 65, 57],
    [42, 63, 55], [43, 66, 58], [44, 67, 59], [45, 69, 61], [46, 69, 61], [47, 70, 62],
    [48, 72, 64], [49, 68, 60], [50, 66, 58], [51, 65, 57], [52, 67, 59], [53, 70, 62],
    [54, 71, 63], [55, 72, 64], [56, 73, 65], [57, 75, 67], [58, 70, 62], [59, 68, 60],
    [60, 64, 56], [61, 60, 52], [62, 65, 57], [63, 67, 59], [64, 68, 60], [65, 69, 61],
    [66, 70, 62], [67, 72, 64], [68, 75, 67], [69, 80, 72]
  ]);

  var options = {
    width: 1000, height: 850, 
    chartArea: {left:75, top:75, width:550, bottom: 40, height: &#39;100%&#39;},
    hAxis: {
      title: &#39;Time&#39;
    },
    vAxis: {
      title: &#39;Popularity&#39;
    },
    series: {
      1: {curveType: &#39;function&#39;}
    }
  };

  var chart = new google.visualization.LineChart(document.getElementById(&#39;chart_div&#39;));
  chart.draw(data, options);
});

<!-- language: lang-html -->

&lt;script src=&quot;https://www.gstatic.com/charts/loader.js&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;chart_div&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月6日 21:54:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75362219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定