score:0
Since Chart.js v2.9.0, you can do this using floating bars. Individual bars can not be specified with syntax [min,max]
.
var canvas = document.getElementById('myChart');
var data = {
labels: ["Test"],
datasets: [{
label: "-10 to 100",
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
borderWidth: 2,
hoverBackgroundColor: "rgba(255,99,132,0.4)",
hoverBorderColor: "rgba(255,99,132,1)",
data: [[-10, 100]],
}]
};
var option = {
scales: {
yAxes:[{
gridLines: {
display:true,
color:"rgba(255,99,132,0.2)"
}
}],
xAxes:[{
gridLines: {
display:false
}
}]
}
};
var myBarChart = Chart.Bar(canvas,{
data:data,
options:option
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="myChart" width="400" height="200"></canvas>
score:1
You can use the code below to set the range of the y-axis in any chart js graph. In this example, the minimum y-axis value is -100 and the maximum y-axis value is 100.
option: {
scales: {
yAxes: [{
ticks: { min: -100, max: 100 },
}],
},
}
But when using the above code, the gap between ticks(stepSize)/ gridline define automatically. So you have to set stepSize value like below. In this example, use stepSize value as 10 and you can see gridlines with a gap of 10.
option: {
scales: {
yAxes: [{
ticks: { min: -100, max: 100, stepSize: 10 },
}],
}
}
So the final code will look like below according to the above question and given an explanation.
var canvas = document.getElementById("myChart");
var data = {
labels: ["Test"],
datasets: [
{
label: "-10 to 100",
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
borderWidth: 2,
hoverBackgroundColor: "rgba(255,99,132,0.4)",
hoverBorderColor: "rgba(255,99,132,1)",
data: [100],
},
],
};
var option = {
scales: {
yAxes: [
{
ticks: { min: -10, max: 100, stepSize: 10 },
},
],
xAxes: [
{
gridLines: {
display: false,
},
},
],
},
};
var myBarChart = Chart.Bar(canvas, {
data: data,
options: option,
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.bundle.js"></script>
<canvas id="myChart" width="400" height="200"></canvas>
score:12
Hi you can try this: you can define the min
or max
value by passing an object to tick
property.
For more detail please visit this link: http://www.chartjs.org/docs/latest/axes/radial/linear.html#tick-options
var option = {
scales: {
yAxes: [
{
stacked: true,
gridLines: {
display: true,
color: "rgba(255,99,132,0.2)"
},
ticks: {
suggestedMax: 100,
suggestedMin: -10
}
}
],
xAxes: [
{
gridLines: {
display: false
}
}
]
}
};
Source: stackoverflow.com
Related Query
- Chart Js Negative Scale
- How to prevent first/last bars from being cut off in a chart with time scale
- chartjs : how to set custom scale in bar chart
- Category scale on Y-axis and time on x-axis in bubble chart in Chartjs
- set y-axis scale manually in a bar chart using angular-chart.js
- impossible to remove scale from radar chart (chart.js)
- Negative bar chart of highcharts in chartjs
- how can i modify scale labels in angular chart js?
- Equal distance grouped bar chart irrespective of scale - chart.js
- How can I style scale numbers in a Polar Area chart (chart.js)
- chart js - bar chart with time scale on Y axis in Hours and Minutes
- Chart.js Polar Area Chart is not scale right
- How to set a time scale to a ChartJS chart from JSON?
- How to select context or scale on chart in chartjs quickchart io to run getValueForPixel?
- How to scale label size radar chart chart.js
- ChartJS Polar Area Chart Scale Removing
- what is wrong with my code ? java script chart position
- How to print a chart rendered by code
- Chart.js Polar Area Chart scale background color
- Smaller scale for volume dataset in Chart JS
- VueJS + Chartjs - Chart only renders after code change
- How do remove the bottom scale on a Chart.js bar chart
- How do I destroy/update Chart Data in this chart.js code example?
- How to start Y Axis Line at 0 from right for negative values in chart js 2?
- 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
- How to make Chart JS ignore the scale between DatasSets
- Chart.js - mixed chart types (line/bar) on time scale causing offset problems after migration to v3
- How to invert scale display on radar chart (chart.js)
- ChartJS Bar chart with time scale - Bars overlap with each other
More Query from same tag
- chart.js - problems with axes options - what am I doing wrong?
- How can I hide point label in chart Js?
- Chart.js: chart not displayed from modules despite no errors - JS
- How to Display Chart.js line-chart from a MVC Controller
- Show value on Mixed chart, Charts.js
- null values for instead of date causes the browser to crash while using chart js
- Synchronous XMLHttpRequest when loading charts.js in to a div
- How to create a linechart with Chart.JS (not filled)
- django chart.js - Query to get count of all distinct values for particular column
- Dynamically update values of a chartjs chart
- ChartJS ReactJS Object of Objects
- Chart.js is it possible to style the labels?
- Using chartjs v2 to show categorical values on axis instead of numeric
- Trying to have Doughnut chart with dql result chartjs
- chart.js fixed bar width issue
- Angularjs lazy load chartjs when in another tab
- Map JSON for Chartjs with Angular 7
- How can I set 3 color to the same chartjs bar?
- AngularJS/ChartJS: Get the current series
- Add Space Between Bars in Angularjs Chartjs
- Different labels in tooltip with chartjs
- getting additional value fields from data source for dx.chartjs doughnut chart
- Multiple line types in ChartJS
- how resetZoom() en multiple charts (ng2charts or chartjs)?
- How to Reset a Chart of Chart.Js?
- ChartJS: Draw line between two data points on hover
- chat,js stacked bar chart (make one dataset into stacked)
- Formatting Data With Charts.JS
- Chart.js - y axis custom label
- chart.js npm module not working