情节设置颜色

Mar*_*sen 2 javascript plotly

我觉得我尝试了一切,但似乎没有任何效果:

            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);
Run Code Online (Sandbox Code Playgroud)

我也试过:

            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);
Run Code Online (Sandbox Code Playgroud)

但是图表保持默认颜色。

那么我怎样才能改变颜色使用 Plotly?

etp*_*ard 5

尝试:

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);
Run Code Online (Sandbox Code Playgroud)

另一个例子在这里