数据不适用于VictoryBar图表

huangapple go评论98阅读模式
英文:

The data does not fit on the VictoryBar chart

问题

我使用Victory库创建了一个图表。我需要构建一个分组的VictoryBar,因此我使用VictoryGroup来实现。

但是我的数据量很大,数据不适合在图表上显示。我应该如何扩大图表,以使y轴数据不混在一起?

如果数据较少,数据会显示在图表上。

我尝试更改'offset'和'barWidth'参数,但没有帮助。

英文:

I make a graph using the Victory library. I need to build a grouped VictoryBar, so I use VictoryGroup to do that.

But I have a lot of data, and the data doesn't fit on the graph. How can I enlarge the graph so that the y-axis data doesn't get mixed up?

If there is less data, the data is placed on the graph

https://codesandbox.io/s/zen-edison-fb8dy4?file=/src/App.js

  1. import "./styles.css";
  2. import plotData from "./data.json";
  3. import React from "react";
  4. import { VictoryBar, VictoryChart, VictoryGroup } from "victory";
  5. export default function App() {
  6. let arr1 = [];
  7. let arr2 = [];
  8. let arr1Sum = 0;
  9. let arr2Sum = 0;
  10. plotData.map((plotData, index) => {
  11. arr1Sum += plotData.ofac_share;
  12. arr2Sum += plotData.non_ofac_share;
  13. });
  14. plotData.map((plotData, index) => {
  15. arr1.push({
  16. y: (plotData.ofac_share / arr1Sum) * 100,
  17. x: plotData.validator
  18. });
  19. arr2.push({
  20. y: (plotData.non_ofac_share / arr2Sum) * 100,
  21. x: plotData.validator
  22. });
  23. });
  24. return (
  25. <VictoryChart>
  26. <VictoryGroup offsetY={10} colorScale={["tomato", "orange"]}>
  27. <VictoryBar horizontal barWidth={3} data={arr1} />
  28. <VictoryBar horizontal barWidth={3} data={arr2} />
  29. </VictoryGroup>
  30. </VictoryChart>
  31. );
  32. }

enter image description here

I tried changing the 'offset' and 'barWidth' parameter, but it didn't help me

答案1

得分: 0

根据文档以及其他布局配置,VictoryChart 组件支持 height 属性:

  1. <VictoryChart height={600}>
  2. <VictoryGroup
  3. offsetY={10}
  4. colorScale={['tomato', 'orange']}
  5. >
  6. <VictoryBar
  7. horizontal
  8. barWidth={3}
  9. data={arr1}
  10. />
  11. <VictoryBar
  12. horizontal
  13. barWidth={3}
  14. data={arr2}
  15. />
  16. </VictoryGroup>
  17. </VictoryChart>;

这是相关Victory文档部分的链接,但以下是该链接摘要的片段:

Victory组件在默认的灰度主题中定义了默认的宽度、高度和填充属性。

希望这能帮到你。

英文:

As per documentation, as well as other layout configurations, the VictoryChart component supports a height property:

  1. &lt;VictoryChart height={600}&gt;
  2. &lt;VictoryGroup
  3. offsetY={10}
  4. colorScale={[&#39;tomato&#39;, &#39;orange&#39;]}
  5. &gt;
  6. &lt;VictoryBar
  7. horizontal
  8. barWidth={3}
  9. data={arr1}
  10. /&gt;
  11. &lt;VictoryBar
  12. horizontal
  13. barWidth={3}
  14. data={arr2}
  15. /&gt;
  16. &lt;/VictoryGroup&gt;
  17. &lt;/VictoryChart&gt;;

Here is the link to the relevant Victory documentation section, but here is a snippet from that link that summarises:

> Victory components have default width, height, and padding props defined in the default grayscale theme.

Hope this helps.

huangapple
  • 本文由 发表于 2023年2月16日 04:03:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464915.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定