Plotly设置颜色

时间:2015-08-25 14:05:47

标签: 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);

我也尝试过:

            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);

然而,图表保持默认颜色。

那么如何使用Plotly?

更改颜色

1 个答案:

答案 0 :(得分:3)

尝试:

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);

另一个例子here