【问题标题】:Plotly.js - Reversing the horizontal bar chart in plotlyPlotly.js - 在 plotly 中反转水平条形图
【发布时间】:2018-02-22 09:37:01
【问题描述】:

我是 plotly 的新手,正在研究条形图示例。我想要做的是让条形图从右到左运行。这是我的 jsfiddle 的链接。

https://jsfiddle.net/ksaluja/w0cx3sw1/1/

目前它是从右到左的默认方式。谢谢!

index.html

<div id="tester" style="width:600px;height:250px;"></div>

scripts.js

var data = [{
  type: 'bar',
  x: [20, 14, 23],
  y: ['giraffes', 'orangutans', 'monkeys'],
  orientation: 'h'
}];

Plotly.newPlot('tester', data);

【问题讨论】:

    标签: bar-chart plotly


    【解决方案1】:

    您需要在layout 对象中使用xaxisautorange: reversed 属性。

    参考下面的例子。

    JSFiddle Demo

    JS:

    var data = [{
      type: 'bar',
      x: [20, 14, 23],
      y: ['giraffes', 'orangutans', 'monkeys'],
      orientation: 'h'
    }];
    
    var layout = {
        xaxis:{
            autorange:'reversed'
        },
        yaxis:{
          side:'right'
        }
    }
    
    Plotly.newPlot('tester', data, layout);
    

    参考资料:

    1. Plotly reversed axis

    2. Plotly Autorange

    【讨论】:

    • 非常感谢!我还试图反转轴标签,以便它们右对齐,而不是从左边开始。
    • @KellyRoper 请提及所有要求 :),您能否查看我更新的答案!
    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    相关资源
    最近更新 更多