【问题标题】:make text on x-axis as bold in google column charts在谷歌柱形图中将 x 轴上的文本设为粗体
【发布时间】:2017-09-14 20:19:29
【问题描述】:

我正在研究 angularjs 谷歌柱形图。我想将横轴上的文本显示为 bold。我浏览了 API,他们建议使用在我的代码中不起作用的 bold:<boolean>。请建议如何将 x 轴上的标签设置为粗体。

js代码:

google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawBasic);

function drawBasic() {
      var data = new google.visualization.DataTable();
      data.addColumn('timeofday', 'Time of Day');
      data.addColumn('number', 'Motivation Level');
      data.addRows([
        [{v: [8, 0, 0], f: '8 am'}, 1],
        [{v: [9, 0, 0], f: '9 am'}, 2],
        [{v: [10, 0, 0], f:'10 am'}, 3],
        [{v: [11, 0, 0], f: '11 am'}, 4],
        [{v: [12, 0, 0], f: '12 pm'}, 5],
        [{v: [13, 0, 0], f: '1 pm'}, 6],
        [{v: [14, 0, 0], f: '2 pm'}, 7],
        [{v: [15, 0, 0], f: '3 pm'}, 8],
        [{v: [16, 0, 0], f: '4 pm'}, 9],
        [{v: [17, 0, 0], f: '5 pm'}, 10],
      ]);

      var options = {
        title: 'Motivation Level Throughout the Day',
        bold:'true',
        hAxis: {
          title: 'Time of Day',
          format: 'h:mm a',
          bold:'true',
          viewWindow: {
            min: [7, 30, 0],
            max: [17, 30, 0]
          }
        },
        vAxis: {
          title: 'Rating (scale of 1-10)',
          bold:"true"
        }
      };

      var chart = new google.visualization.ColumnChart(
        document.getElementById('chart_div'));

      chart.draw(data, options);
    }

html代码:

<div id="chart_div"></div>

【问题讨论】:

    标签: javascript angularjs charts google-visualization


    【解决方案1】:

    使 x 轴 刻度标记 使用粗体 --> hAxis.textStyle.bold

        hAxis: {
          title: 'Time of Day',
          format: 'h:mm a',
          textStyle: {
            bold:'true',
          },
          viewWindow: {
            min: [7, 30, 0],
            max: [17, 30, 0]
          }
    

    使x轴标题标签加粗 --> hAxis.titleTextStyle.bold

        hAxis: {
          title: 'Time of Day',
          format: 'h:mm a',
          titleTextStyle: {
            bold:'true',
          },
          viewWindow: {
            min: [7, 30, 0],
            max: [17, 30, 0]
          }
    

    【讨论】:

      【解决方案2】:

      在您的选项对象中使用以下代码
      hAxis: { title: 'Time of Day', format: 'h:mm a', titleTextStyle : {bold: 'true'}, viewWindow: { min: [7, 30, 0], max: [17, 30, 0] } }, vAxis: { title: 'Rating (scale of 1-10)', titleTextStyle : {bold: 'true'} }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多