简体   繁体   English

删除 Google 时间线图表中的粗体刻度标签

[英]Remove bold tick labels in Google Timeline chart

In the following image:在下图中:

在此处输入图片说明

12 AM / 12 PM / 12 AM is bold for the horizontal label.水平标签的 12 AM / 12 PM / 12 AM 为粗体。 How do I make all of the labels non-bold?如何使所有标签不加粗? I didn't see an option in their documentation: https://developers.google.com/chart/interactive/docs/gallery/timeline .我在他们的文档中没有看到一个选项: https : //developers.google.com/chart/interactive/docs/gallery/timeline

Here is an example of it in jsfiddle: https://jsfiddle.net/0f86vLrg/ :这是 jsfiddle 中的一个示例: https ://jsfiddle.net/0f86vLrg/:

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="timeline" style="height: 180px;"></div>
  google.charts.load('current', {
    'packages': ['timeline']
  });
  google.charts.setOnLoadCallback(drawChart);

  function drawChart() {
    var container = document.getElementById('timeline');
    var chart = new google.visualization.Timeline(container);
    var dataTable = new google.visualization.DataTable();
    dataTable.addColumn({
      type: 'string',
      id: 'Room'
    });
    dataTable.addColumn({
      type: 'string',
      id: 'Name'
    });
    dataTable.addColumn({
      type: 'date',
      id: 'Start'
    });
    dataTable.addColumn({
      type: 'date',
      id: 'End'
    });
    dataTable.addRows([
      ['Magnolia Room', 'Google Charts', new Date(0, 0, 0, 14, 0, 0), new Date(0, 0, 0, 15, 0, 0)],
      ['Magnolia Room', 'App Engine', new Date(0, 0, 0, 15, 0, 0), new Date(0, 0, 0, 16, 0, 0)]
    ]);

    var options = {
      timeline: {
        showRowLabels: false
      },
      avoidOverlappingGridLines: false
    };

    chart.draw(dataTable, options);
  }

as you've found, there are no timeline options for styling the x-axis labels.正如您所发现的,没有用于设置 x 轴标签样式的时间线选项。
but you can change them manually, on the chart's 'ready' event.但您可以在图表的'ready'事件中手动更改它们。

google.visualization.events.addListener(chart, 'ready', function () {
  var labels = container.getElementsByTagName('text');
  Array.prototype.forEach.call(labels, function(label) {
    label.setAttribute('font-weight', 'normal');
  });
});

see following working snippet...请参阅以下工作片段...

 google.charts.load('current', { 'packages': ['timeline'] }); google.charts.setOnLoadCallback(drawChart); function drawChart() { var container = document.getElementById('timeline'); var chart = new google.visualization.Timeline(container); var dataTable = new google.visualization.DataTable(); dataTable.addColumn({ type: 'string', id: 'Room' }); dataTable.addColumn({ type: 'string', id: 'Name' }); dataTable.addColumn({ type: 'date', id: 'Start' }); dataTable.addColumn({ type: 'date', id: 'End' }); dataTable.addRows([ ['Magnolia Room', 'Google Charts', new Date(0, 0, 0, 14, 0, 0), new Date(0, 0, 0, 15, 0, 0)], ['Magnolia Room', 'App Engine', new Date(0, 0, 0, 15, 0, 0), new Date(0, 0, 0, 16, 0, 0)] ]); var options = { timeline: { showRowLabels: false }, avoidOverlappingGridLines: false }; google.visualization.events.addListener(chart, 'ready', function() { var labels = container.getElementsByTagName('text'); Array.prototype.forEach.call(labels, function(label) { label.setAttribute('font-weight', 'normal'); }); }); chart.draw(dataTable, options); }
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="timeline" style="height: 180px;"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM