Replies: 2 comments 5 replies
-
You can implement this yourself already with a scriptable option for the const cantGrowBiggerAs = 40;
const options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'pink'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderColor: 'orange'
}
]
},
options: {
scales: {
y: {
max: (ctx) => {
let max = Number.NEGATIVE_INFINITY;
ctx.chart.data.datasets.forEach(dataset => {
let datasetMax = Math.max(...dataset.data);
max = datasetMax > max ? datasetMax : max;
})
return max >= cantGrowBiggerAs ? cantGrowBiggerAs : null;
}
}
}
}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options); |
Beta Was this translation helpful? Give feedback.
2 replies
-
I was going to try LeeLenaleee's version but my data is in x/y pairs as in |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The linear scale configurations currently have min/max and suggestedMin/suggestedMax. Min/max fixes the scale endpoints and suggestedMin/suggestedMax fixes the scale endpoints at initial draw but allows them to expand based on the data.
I would like to suggest a third type, a form of "not to exceed" which would allow the chart to select the appropriate endpoints until the data reached these values at which point the endpoints would be fixed. It's essentially the reverse of the suggestedMin/suggestedMax.
Rationale: Suppose a set of data collected from a real world system that, on average, is centered on 0 with a standard deviation of 5. Most data will be within two standard deviations from the mean and the vast majority would be within three. It is possible for this real world system to generate valid data points that lie far outside three standard deviations.
The idea then is that the graph would show the data as is but have the scale min/max limited by the new min/max property to the values of +/- three standard deviations. This would allow the graph to grow if data begins to appear that is up to 3 standard deviations away but otherwise autoscale to fit the data that will naturally be much closer to the mean. It also prevents the scale from being stretched out in the event of an extreme datapoint (in the case of a line chart, showing lines that extend beyond the limit) where it would not be correct to filter out the exxtreme point as it is valid data but it's not necessary to represent it accurately on the plot (one can see the lines extending off the edge to know that an extreme point is present but the point itself does not need to be visible).
Implementation: Where suggestedMin/suggestedMax implement this by the basic idea of scale_min = min(data, suggestedMin) or scale_max = max(data, suggestedMax) the new settings would implement in basically the form scale_min = max( min(data), notToExceedMin) and scale_max = min( max(data), notToExceedMax).
Beta Was this translation helpful? Give feedback.
All reactions