简体   繁体   English

如何为胜利轴上的刻度动态创建 y 轴值?

[英]How to dynamically create y axis values for ticks on victory axis?

I have created a victory bar chart to show employee attrition.我创建了一个胜利条形图来显示员工流失率。 But y-axis of the chart is showing floating values instead of an integer but as employees' count can not be in floating point I want to show y-axis values in integer number only so the solution for the same is to define custom tick values as但是图表的 y 轴显示的是浮点值而不是 integer 但由于员工的计数不能是浮点数,我想在 integer 数字中显示 y 轴值,因此解决方案是定义自定义刻度值作为

 <VictoryAxis tickValues={[2, 4, 6, 8]}/>

But I don't know how I dynamically generate ticks array for my y-axis values.但我不知道如何为我的 y 轴值动态生成刻度数组。 Here is how my graph looks:这是我的图表的外观:

在此处输入图像描述

How specifically you get the values will vary depending on what your data is, but you can generally get them by grabbing a max and a min, and then getting evenly spaced values in between (or pushing the maximum up in order to do so).您获取值的具体程度取决于您的数据是什么,但您通常可以通过获取最大值和最小值来获取它们,然后在两者之间获取均匀间隔的值(或将最大值推高以便这样做)。 You can then pass the generated values to you VictoryAxis like this:然后,您可以像这样将生成的值传递给VictoryAxis

const generatedValues = // code to generate the wanted values

...

<VictoryAxis tickValues={generatedValues}>

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

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