score:1
This may not be the cleanest way but you can play with it as you see fit.
In short, you need to create a function that finds the max value out of all your dataSets arrays and in yAxes.ticks set max to that functions return value.
More details below
Referencing here first:
data:{
labels: labels.data,
datasets: dataSets //talking about this first
}
Create a function that will go through these arrays and get the max of all arrays. I did it using this but you can do it better I'm sure:
function getMax(){
var max = 0;
dataSets.forEach(function(x, i){
max = Math.max(max, Math.max.apply(null, x.data));
});
return max + 2;
}
Then in your return
in yAxes you should be able to have:
ticks: {
beginAtZero: false,
max: getMax()
},
score:1
You can find the min and max of your dataset, then add/subtract a percentage of the difference (range).
For example, say you use 1% of the range.
[0.1, 0.2, 0.5] gives (1%)x(0.5-0.1)=0.004, so [min,max]=[0.096,0.504].
[1500, 1800, 3500, 3600] gives (1%)x(3600-1500)=21, so [min,max]=[1479,3621].
Source: stackoverflow.com
Related Query
- React chart : prevent chart's canvas scaling with height and width
- Chart.js automatic scaling
- ChartJS chart not scaling after adding values
- Y scaling relative to the max value in my ChartJS chart
- Chart js Backgroundimage Scaling
- Automatic resize of chart - AngularChartJS
- what is wrong with my code ? java script chart position
- How to print a chart rendered by code
- VueJS + Chartjs - Chart only renders after code change
- How do I destroy/update Chart Data in this chart.js code example?
- getting additional value fields from data source for dx.chartjs doughnut chart
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Trouble with chart scaling and zooming using Chart.js and chartjs-zoom-plugin
- Control Scaling of Canvas When dragged out of chart limit
- Getting the HTML code of a chart created by chart.js
- How to run Chart.js samples using source code
- how to not repeat code while creating multiple charts in chart js
- Set height of chart in Chart.js
- Dynamically update values of a chartjs chart
- How to add text inside the doughnut chart using Chart.js?
- How to clear a chart from a canvas so that hover events cannot be triggered?
- In Chart.js set chart title, name of x axis and y axis?
- Limit labels number on Chart.js line chart
- Chart.js - How to set a line chart dataset as disabled on load
- Charts.js graph not scaling to canvas size
- chart js 2 how to set bar width
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- Chartjs Bar Chart showing old data when hovering
- Chart.js Show labels on Pie chart
- Chart Js Change Label orientation on x-Axis for Line Charts
More Query from same tag
- How to get data on chart based on selected date (Filtering data Chart JS with datepicker)
- Add background text in ChartJS
- Convert a dynamic piechart from CanvasJS to Google Charts?
- angular-chart.js not rendering any chart
- Can't render multiple responsive canvas graphs in different tabs
- Custom background limits for Doughnut (Gauge)
- ChartJS/ ChartJS-plugin annotation set height of vertical line
- Grouping by month with series of epoch timestamps in Chart.js
- Charts.js line chart: Show the most recent date on x-axis when setting ticks.maxTicksLimit
- charts js, doughnut chart not rendering tooptips correctly
- chart does not change the values when the variable changes the value
- Can't display proper time on chart.js timeline
- ChartJS: How to get labels, legend, title to show up?
- Chartjs - make line start at ... but maintain x-axis data
- chart.js in mvc graph are not show
- Chart.js2 Radar, how to configure the label padding/spacing?
- Chart.js how to set cutoutPercentages for each dataset
- ChartJS ReactJS Object of Objects
- How to avoid detached HTMLCanvasElements when updating canvas with JavaScript?
- Chartjs isn't rendering bar chart, even though chart variable shows correctly when console logged
- ChartJS only show me data when I zoom-in or zoom-out
- Laravel query builder for Charts.js
- How to plot a line graph with x and y data
- Unable to display chartjs chart in Shiny UI
- Chart.js - Multiple generateLegend() functions on same page
- 'require is not defined' error when attempting to use chartjs in javascript code
- Chart js show levels on top. (Bar chart with Stacked group)
- Create data in data with Chartjs
- Line ChartJS empty / null values doesn't break the line
- Category scale on Y-axis and time on x-axis in bubble chart in Chartjs