Plotly.js - Reversing the horizontal bar chart in plotly

不想你离开。 提交于 2019-12-12 05:33:26

问题


I am new to plotly and am working of a bar chart example. What I want to do is have the bar chart run from right to left. Here is a link to my jsfiddle.

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

Currently it is going the default way from right to left. Thanks!

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

回答1:


You need to use the autorange: reversed property of xaxis in layout object.

Refer the below example.

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

References:

  1. Plotly reversed axis

  2. Plotly Autorange



来源:https://stackoverflow.com/questions/46201532/plotly-js-reversing-the-horizontal-bar-chart-in-plotly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!