Closed kmzeitgleich closed 6 months ago
A Victory axis supplied with numerical data will assign the point [0,0]
to the origin. However, charts like VictoryBar
can also accommodate categories on the X axis, which do not start at the origin. You can do this by providing the x
values as a string
, or by coercing them with a data accessor in the below the example.
<VictoryChart domainPadding={20}>
<VictoryBar
data={[
{x: 0, y: 3},
{x: 1, y: 4},
{x: 2, y: 2},
{x: 3, y: 1},
{x: 4, y: 1},
]}
x={(datum) => datum.x.toString()}
/>
</VictoryChart>
I could do that, but then I lose the linear scale. I will not have gaps in my x values, like if you add x: 8, y: 2 and have not data between that
It's important to understand that a Bar chart is a type of visualization that displays qualitative data across discrete values. Discrete values are non-linear and are typically called "categorical" data. You may want to consider a different type of visualization in your use case.
Here is a good reference for visualization types: https://www.data-to-viz.com/
However, you can still achieve this using the categories
property and specifying the linear range of your data.
<VictoryChart domainPadding={20}>
<VictoryBar
data={[
{x: 0, y: 3},
{x: 1, y: 4},
{x: 2, y: 2},
{x: 3, y: 1},
{x: 4, y: 1},
{x: 8, y: 4},
]}
categories={{
x: Array.from(Array(10).keys().map(x => x.toString()))
}}
/>
</VictoryChart>
Ok, that should be a good enough workaround
Is there an existing issue for this?
Code of Conduct
Victory version
37.0.2
Code Sandbox link
No response
Bug report
Steps to reproduce
Expected behavior
No response
Actual behavior
No response
Environment