My Objective to show the y-axis value dynamically in the chart. If my data contains below 100 i.e(highest value in data = 75) then it should show 80 as highest number in y-axis. it should not show 500 in the y-axis.
<Bar
data={this.state.data}
width={400}
height='150'
options={{
tooltips: {
mode: 'point',
intersect: false,
},
responsive: true,
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: false,
ticks: {
beginAtZero: true,
min: 0,
max: 500
}
}, {
id: "bar-stacked",
stacked: true,
display: false,
ticks: {
beginAtZero: true,
min: 0,
max: 500
},
type: 'linear'
}]
}
}}
/>
Is it possible to make it dynamic? If yes, Can anyone help me in this query?
To dynamically compute the ticks you need a couple things.
To find the maximum value in the array of (presumably objects) data you can do something similar to the following.
[edit]
You mention in comments your data has this shape
To find the maximum value in the data you can simply spread
data
intoMath.max
.[/edit]
To compute the max tick you can compute the next "chunked" tick after the maximum computed from data with something similar to:
or
The difference between the two is what to "round" to if the value is even divided by the chunk amount, i.e. if data max 80 should have max tick of 80 or 90. This first would yield 90 while the second would yield 80.
Put these two together to compute the ticks to display in the graph.