简体   繁体   English

图表-具有圆角的反向垂直条形图具有倒转的末端

[英]Recharts - Reversed Vertical Barchart with Rounded Corners have Inverted Ends

I want to create a bar chart with rounded bars that looks like this, but have the bars in reverse 我想创建一个圆条,看起来像这样的柱状图,但在相反的酒吧

在此处输入图片说明

But after adding the reversed prop to the XAxis component, it becomes like this 但是,增加的反向支撑于x轴组件后,就变成这样

在此处输入图片说明

Here is my code i did from one of the examples in Recharts 这里是我的代码来自于Recharts一个例子做

 const {BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend} = Recharts; const data = [ {name: 'Page A', uv: 4000, pv: 2400, amt: 2400}, {name: 'Page B', uv: 3000, pv: 1398, amt: 2210}, {name: 'Page C', uv: 2000, pv: 9800, amt: 2290}, {name: 'Page D', uv: 2780, pv: 3908, amt: 2000}, {name: 'Page E', uv: 1890, pv: 4800, amt: 2181}, ]; const SimpleBarChart = React.createClass({ render () { return ( <BarChart width={ 600 } height={ 400 } data={ data } maxBarSize={ 20 } layout={ 'vertical' }> <CartesianGrid strokeDasharray="3 3" /> <XAxis type={ 'number' } orientation={ 'top' } reversed /> <YAxis type={ 'category' } orientation={ 'right' } dataKey={ 'name' } /> <Bar dataKey={ 'pv' } fill={ '#8884d8' } radius={ 20 }/> </BarChart> ); } }) ReactDOM.render( <SimpleBarChart />, document.getElementById('container') ); 
 body { margin: 0; } #container { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding: 10px; width: 800px; height: 800px; background-color: #fff; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script> <script src="https://npmcdn.com/react@15.6.2/dist/react-with-addons.min.js"></script> <script src="https://npmcdn.com/react-dom@15.6.2/dist/react-dom.min.js"></script> <script src="https://npmcdn.com/prop-types@15.6.2/prop-types.min.js"></script> <script src="https://npmcdn.com/recharts@1.4.2/umd/Recharts.min.js"></script> <div id="container"> <!-- This element's contents will be replaced with your component. --> </div> 

Update - I tried removing the reversed prop and just added data with negative values to see if the same inverted bars would happen and the results were the same. 更新 -我试图消除道具,只是负值增加的数据,看是否相同倒杆会发生,结果是一样的。 So it would seem that when the values are negative and the bars are in the vertical layout, rounded corners will just happen to act this way. 因此,它似乎是当值是负和酒吧都在垂直布局,圆润的边角会恰好这样的行为。 Does anyone have any idea what is going on. 没有人有任何想法是怎么回事。

Update - seems like this was a bug on Recharts side and was fixed in a newer version 更新 -看起来这是在Recharts侧的错误,并固定在一个较新版本

You should specify type in XAxis to be number 你应该在X轴指定类型是数字

<BarChart 
  width={600} 
  height={300} 
  data={data} 
  layout="vertical"
  margin={{top: 5, right: 30, left: 20, bottom: 5}}
>
  <XAxis type="number"/>
  <YAxis type="category" dataKey="name" />
  <CartesianGrid strokeDasharray="3 3"/>
  <Tooltip/>
  <Legend />
  <Bar dataKey="pv" fill="#8884d8" />
  <Bar dataKey="uv" fill="#82ca9d" />
</BarChart>

Because the default value of type in XAxis is 'category'. 由于类型的X轴的默认值是“类别”。

The latest version of Recharts addresses this issue. Recharts的最新版本解决了这个问题。 Once updated, it works fine now 一旦更新,现在工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM