Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌图表API-不同颜色的烛台_Javascript_Google Visualization - Fatal编程技术网

Javascript 谷歌图表API-不同颜色的烛台

Javascript 谷歌图表API-不同颜色的烛台,javascript,google-visualization,Javascript,Google Visualization,在使用谷歌图表API时,有没有办法使某些烛台的颜色不同 例如,请查看以下(可编辑)烛台图表: ​有没有办法,比如说,只把“星期二”的烛台调成红色,而把其余的烛台调成蓝色/白色?似乎没有图表选项来设置 一种可能性是根据数据构建两个系列,并为每个系列设置不同的颜色。必须更改输入数据Tue数据移动到第二个系列,所有其他值均为零: var data = google.visualization.arrayToDataTable([ ['Mon', 20, 28, 38, 45,

在使用谷歌图表API时,有没有办法使某些烛台的颜色不同

例如,请查看以下(可编辑)烛台图表:


​有没有办法,比如说,只把“星期二”的烛台调成红色,而把其余的烛台调成蓝色/白色?

似乎没有图表选项来设置

一种可能性是根据数据构建两个系列,并为每个系列设置不同的颜色。必须更改输入数据<代码>Tue数据移动到第二个系列,所有其他值均为零:

    var data = google.visualization.arrayToDataTable([
      ['Mon', 20, 28, 38, 45,  0, 0, 0, 0],
      ['Tue',  0,  0,  0,  0, 31, 38, 55, 66,],
      ['Wed', 50, 55, 77, 80,  0, 0, 0, 0],
      ['Thu', 77, 77, 66, 50,  0, 0, 0, 0],
      ['Fri', 68, 66, 22, 15,  0, 0, 0, 0]
      // Treat first row as data as well.
    ], true);

    var options = {
        legend: 'none',
        bar: {
            groupWidth: 100
        },
        series: {
            0: {color: '#4682B4'},
            1: {color: '#FF8C00'}
        }
    };
看。不是很漂亮,因为第二个系列有偏移量

另一种可能是更改SVG元素属性值。每个烛台都是使用如下方式构建的:

<g>
<rect x="235" y="279" width="2" height="115" stroke="none" stroke-width="0" fill="#4682b4"></rect>
<rect x="213" y="312" width="47" height="44" stroke="#4682b4" stroke-width="2" fill="#4682b4"></rect>
</g>
请参见使用硬编码数据更新


注意:填充颜色值是小写的,因此如果搜索4682B4,将找不到任何内容。

谢谢@anto,我将接受此选项,因为它是正确的答案,非常有用。我最终使用了一个组合图,其中不相关的蜡烛被一系列折线图(烛台值为null)替换,而相关的烛台保留在适当的位置(线值为null)。
<g>
<rect x="235" y="279" width="2" height="115" stroke="none" stroke-width="0" fill="#4682b4"></rect>
<rect x="213" y="312" width="47" height="44" stroke="#4682b4" stroke-width="2" fill="#4682b4"></rect>
</g>
    var cSticks = document.querySelectorAll('rect[fill="#4682b4"]');

    cSticks[2].setAttribute('fill', '#ff8c00');
    cSticks[3].setAttribute('fill', '#ff8c00');
    cSticks[3].setAttribute('stroke', '#ff8c00');