【问题标题】:Google chart grid background with multiple colors具有多种颜色的 Google 图表网格背景
【发布时间】:2018-10-09 11:16:00
【问题描述】:

我在下面创建了一个只有一点的简单散点图,(我总是只有一个点)

在上图中,我想将左上角和右下角的框标记为一种颜色,其余两个框标记为不同的颜色,以向用户建议它们的价值是好是坏。

左上和右下是好的(绿色),右上和左下是坏的(红色)。

仅供参考,我正在添加哪些颜色去哪里的示例图片

我进行了很多搜索,但找不到任何解决方案。我尝试了线性渐变,但无法按照我想要的方式使用线性渐变。

是否可以在谷歌图表中为网格框着色?有没有其他方法可以做到这一点?

谢谢。

【问题讨论】:

    标签: javascript css svg charts google-visualization


    【解决方案1】:

    没有用于指定背景颜色的配置选项。
    但您可以使用 堆叠区域 系列来添加颜色。

    对于有问题的图表,您需要 5 个系列。

    1) 分散
    2) 区域 - 左低
    3) 区域 - 左高
    4) 区域 - 右低
    5)区域 - 右高

    请参阅以下工作 sn-p...

    google.charts.load('current', {
      packages:['corechart']
    }).then(function () {
      var dataTable = new google.visualization.DataTable({
        cols: [
          {label: 'X', type: 'number'},
          {label: 'Left-Low', type: 'number'},
          {label: 'Left-High', type: 'number'},
          {label: 'Right-Low', type: 'number'},
          {label: 'Right-High', type: 'number'},
          {label: 'Y', type: 'number'}
        ],
        rows: [
          // scatter
          {c:[{v: 14}, {v: 130}, null, null, null, null]},
          // colors
          {c:[{v: 1}, null, {v: 170}, {v: 130}, null, null]},
          {c:[{v: 6}, null, {v: 170}, {v: 130}, null, null]},
          {c:[{v: 6}, null, {v: null}, {v: null}, {v: 170}, {v: 130}]},
          {c:[{v: 15}, null, {v: null}, {v: null}, {v: 170}, {v: 130}]},
        ]
      });
    
      var options = {
        colors: ['#ffffff'],
        legend: 'none',
        hAxis: {
          ticks: [1, 6, 15],
          title: 'Coleman-Liau Index'
        },
        height: 400,
        isStacked: true,
        series: {
          // Left-Low
          1: {
            areaOpacity: 1,
            color: '#e53935',
            enableInteractivity: false,
            type: 'area',
            visibleInLegend: false
          },
    
          // Left-High
          2: {
            areaOpacity: 1,
            color: '#43a047',
            enableInteractivity: false,
            type: 'area',
            visibleInLegend: false
          },
    
          // Right-Low
          3: {
            areaOpacity: 1,
            color: '#43a047',
            enableInteractivity: false,
            type: 'area',
            visibleInLegend: false
          },
    
          // Right-High
          4: {
            areaOpacity: 1,
            color: '#e53935',
            enableInteractivity: false,
            type: 'area',
            visibleInLegend: false
          }
        },
        seriesType: 'scatter',
        vAxis: {
          ticks: [40, 170, 300],
          title: 'Talking Speed (WpM)'
        }
      };
    
      var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
      chart.draw(dataTable, options);
    });
    <script src="https://www.gstatic.com/charts/loader.js"></script>
    <div id="chart_div"></div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多