Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 绘图设置颜色_Javascript_Plotly - Fatal编程技术网

Javascript 绘图设置颜色

Javascript 绘图设置颜色,javascript,plotly,Javascript,Plotly,我觉得我什么都试过了,但似乎都不管用: var charData = [{ x: x1, y: y, type: 'bar', color: 'rgb(31,119,180)', orientation: 'h', name: 'Nuv

我觉得我什么都试过了,但似乎都不管用:

            var charData = [{
                    x: x1,
                    y: y,
                    type: 'bar',
                    color: 'rgb(31,119,180)',
                    orientation: 'h',
                    name: 'Nuværende',
                    bar: {
                        color: 'rgb(rgb(31, 114, 225)'
                    }
                }, {
                    x: x2,
                    y: y,
                    type: 'bar',
                    orientation: 'h',
                    name: 'Forventet'
                }],
                layout = {
                    title: 'Brugere',
                    barmode: 'stack',
                    legend: {
                        orientation: 'h'

                    }
                };
            Plotly.newPlot(area,charData,layout);
我也试过:

            var charData = [{
                    x: x1,
                    y: y,
                    type: 'bar',
                    color: 'rgb(31,119,180)',
                    orientation: 'h',
                    name: 'Nuværende',
                    color: '#23b7e5'
                }, {
                    x: x2,
                    y: y,
                    type: 'bar',
                    orientation: 'h',
                    name: 'Forventet'
                }],
                layout = {
                    title: 'Brugere',
                    barmode: 'stack',
                    legend: {
                        orientation: 'h'

                    }
                };
            Plotly.newPlot(area,charData,layout);
但是,图表将保留默认颜色

那么如何使用
绘图更改颜色呢?
试试:

var charData = [{
                x: x1,
                y: y,
                type: 'bar',
                orientation: 'h',
                name: 'Nuværende',
                marker: {
                  color: '#23b7e5'
                }
            }],
            layout = {
                title: 'Brugere',
                barmode: 'stack',
                legend: {
                    orientation: 'h'

                }
            };
        Plotly.newPlot(area,charData,layout);
另一个例子