Chart.js Bar Chart - how to chart bars from 0
I'd like to chart the bars extending from zero so that positive numbers grow upwards (as normal) but negative numbers grow downwards from zero. I get instead all numbers starting from a negative baseline.
chart.js
add a comment |
I'd like to chart the bars extending from zero so that positive numbers grow upwards (as normal) but negative numbers grow downwards from zero. I get instead all numbers starting from a negative baseline.
chart.js
add a comment |
I'd like to chart the bars extending from zero so that positive numbers grow upwards (as normal) but negative numbers grow downwards from zero. I get instead all numbers starting from a negative baseline.
chart.js
I'd like to chart the bars extending from zero so that positive numbers grow upwards (as normal) but negative numbers grow downwards from zero. I get instead all numbers starting from a negative baseline.
chart.js
chart.js
asked Jun 3 '15 at 6:50
user1860288user1860288
1202312
1202312
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
The other answers didn't work for me. However, I did manage to find another config option that did work for me.
var options = {
// All of my other bar chart option here
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
Passing this for my chart options give me a bar chart with the scale starting at 0.
2
Thanks! This should be the accepted answer.
– GG.
Nov 6 '16 at 1:43
add a comment |
I think you're looking for something like this
Fiddle
HTML
<canvas id="myChart" width="500" height="250"></canvas>
JS
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July", "August"],
datasets: [
{
data: [65, 59, 80, 81, 56, 55, 40, -30]
}
]
};
var options = {
scaleBeginAtZero: false
};
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
I think you meant{ scaleBeginAtZero: true }
, which gives partially the effect I wanted. However, the y-axis does not begin below -30. When I triedoptions = { scaleOverride: true, scaleStartValue: -50, scaleStepWidth: 50, scaleSteps: 3, scaleBeginAtZero: true, }
, then then bars all spring from the bottom again.
– user1860288
Jun 3 '15 at 13:11
add a comment |
You can use d3.js for the intended behaviour. Here is a good post regarding that.
Or
You can also follow this article tweaking the plotkit chart to show the downwards negative bar.
To make it work it with chart.js(though not advisable as this is not supported in Chart.js) you can use this github pull and instead of using the global configuration object, i.e. setting:
Chart.defaults.global.responsive = true;
Chart.defaults.global.scaleBeginAtZero = false;
Chart.defaults.global.barBeginAtOrigin = false,
Chart.defaults.global.animation = false;
use a separate config object and pass it into the chart constructor:
var chartOptions = {
responsive:true,
scaleBeginAtZero:false,
barBeginAtOrigin:true
}
var chartInstance = new Chart(ctx).Bar(myChartData, chartOptions);
add a comment |
I'm using Chart.js version 2.0.2 and this could be achieved using yAxes.min
, and if the chart is empty you could use yAxes.suggestedMax
Example:
options:{
.
.
.
scales{
yAxes:[{
min:0,
//this value will be overridden if the scale is greater than this value
suggestedMax:10
}]
}
add a comment |
public barChartOptions: any = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true}
}]
},
}
add a comment |
use beginat zero like below:
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30612813%2fchart-js-bar-chart-how-to-chart-bars-from-0%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
The other answers didn't work for me. However, I did manage to find another config option that did work for me.
var options = {
// All of my other bar chart option here
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
Passing this for my chart options give me a bar chart with the scale starting at 0.
2
Thanks! This should be the accepted answer.
– GG.
Nov 6 '16 at 1:43
add a comment |
The other answers didn't work for me. However, I did manage to find another config option that did work for me.
var options = {
// All of my other bar chart option here
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
Passing this for my chart options give me a bar chart with the scale starting at 0.
2
Thanks! This should be the accepted answer.
– GG.
Nov 6 '16 at 1:43
add a comment |
The other answers didn't work for me. However, I did manage to find another config option that did work for me.
var options = {
// All of my other bar chart option here
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
Passing this for my chart options give me a bar chart with the scale starting at 0.
The other answers didn't work for me. However, I did manage to find another config option that did work for me.
var options = {
// All of my other bar chart option here
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
Passing this for my chart options give me a bar chart with the scale starting at 0.
edited May 25 '17 at 20:13
Black Mamba
3,11222441
3,11222441
answered Sep 26 '16 at 14:34
KbyeKbye
29135
29135
2
Thanks! This should be the accepted answer.
– GG.
Nov 6 '16 at 1:43
add a comment |
2
Thanks! This should be the accepted answer.
– GG.
Nov 6 '16 at 1:43
2
2
Thanks! This should be the accepted answer.
– GG.
Nov 6 '16 at 1:43
Thanks! This should be the accepted answer.
– GG.
Nov 6 '16 at 1:43
add a comment |
I think you're looking for something like this
Fiddle
HTML
<canvas id="myChart" width="500" height="250"></canvas>
JS
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July", "August"],
datasets: [
{
data: [65, 59, 80, 81, 56, 55, 40, -30]
}
]
};
var options = {
scaleBeginAtZero: false
};
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
I think you meant{ scaleBeginAtZero: true }
, which gives partially the effect I wanted. However, the y-axis does not begin below -30. When I triedoptions = { scaleOverride: true, scaleStartValue: -50, scaleStepWidth: 50, scaleSteps: 3, scaleBeginAtZero: true, }
, then then bars all spring from the bottom again.
– user1860288
Jun 3 '15 at 13:11
add a comment |
I think you're looking for something like this
Fiddle
HTML
<canvas id="myChart" width="500" height="250"></canvas>
JS
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July", "August"],
datasets: [
{
data: [65, 59, 80, 81, 56, 55, 40, -30]
}
]
};
var options = {
scaleBeginAtZero: false
};
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
I think you meant{ scaleBeginAtZero: true }
, which gives partially the effect I wanted. However, the y-axis does not begin below -30. When I triedoptions = { scaleOverride: true, scaleStartValue: -50, scaleStepWidth: 50, scaleSteps: 3, scaleBeginAtZero: true, }
, then then bars all spring from the bottom again.
– user1860288
Jun 3 '15 at 13:11
add a comment |
I think you're looking for something like this
Fiddle
HTML
<canvas id="myChart" width="500" height="250"></canvas>
JS
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July", "August"],
datasets: [
{
data: [65, 59, 80, 81, 56, 55, 40, -30]
}
]
};
var options = {
scaleBeginAtZero: false
};
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
I think you're looking for something like this
Fiddle
HTML
<canvas id="myChart" width="500" height="250"></canvas>
JS
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July", "August"],
datasets: [
{
data: [65, 59, 80, 81, 56, 55, 40, -30]
}
]
};
var options = {
scaleBeginAtZero: false
};
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).Bar(data, options);
answered Jun 3 '15 at 7:27
fatCopfatCop
1,05172445
1,05172445
I think you meant{ scaleBeginAtZero: true }
, which gives partially the effect I wanted. However, the y-axis does not begin below -30. When I triedoptions = { scaleOverride: true, scaleStartValue: -50, scaleStepWidth: 50, scaleSteps: 3, scaleBeginAtZero: true, }
, then then bars all spring from the bottom again.
– user1860288
Jun 3 '15 at 13:11
add a comment |
I think you meant{ scaleBeginAtZero: true }
, which gives partially the effect I wanted. However, the y-axis does not begin below -30. When I triedoptions = { scaleOverride: true, scaleStartValue: -50, scaleStepWidth: 50, scaleSteps: 3, scaleBeginAtZero: true, }
, then then bars all spring from the bottom again.
– user1860288
Jun 3 '15 at 13:11
I think you meant
{ scaleBeginAtZero: true }
, which gives partially the effect I wanted. However, the y-axis does not begin below -30. When I tried options = { scaleOverride: true, scaleStartValue: -50, scaleStepWidth: 50, scaleSteps: 3, scaleBeginAtZero: true, }
, then then bars all spring from the bottom again.– user1860288
Jun 3 '15 at 13:11
I think you meant
{ scaleBeginAtZero: true }
, which gives partially the effect I wanted. However, the y-axis does not begin below -30. When I tried options = { scaleOverride: true, scaleStartValue: -50, scaleStepWidth: 50, scaleSteps: 3, scaleBeginAtZero: true, }
, then then bars all spring from the bottom again.– user1860288
Jun 3 '15 at 13:11
add a comment |
You can use d3.js for the intended behaviour. Here is a good post regarding that.
Or
You can also follow this article tweaking the plotkit chart to show the downwards negative bar.
To make it work it with chart.js(though not advisable as this is not supported in Chart.js) you can use this github pull and instead of using the global configuration object, i.e. setting:
Chart.defaults.global.responsive = true;
Chart.defaults.global.scaleBeginAtZero = false;
Chart.defaults.global.barBeginAtOrigin = false,
Chart.defaults.global.animation = false;
use a separate config object and pass it into the chart constructor:
var chartOptions = {
responsive:true,
scaleBeginAtZero:false,
barBeginAtOrigin:true
}
var chartInstance = new Chart(ctx).Bar(myChartData, chartOptions);
add a comment |
You can use d3.js for the intended behaviour. Here is a good post regarding that.
Or
You can also follow this article tweaking the plotkit chart to show the downwards negative bar.
To make it work it with chart.js(though not advisable as this is not supported in Chart.js) you can use this github pull and instead of using the global configuration object, i.e. setting:
Chart.defaults.global.responsive = true;
Chart.defaults.global.scaleBeginAtZero = false;
Chart.defaults.global.barBeginAtOrigin = false,
Chart.defaults.global.animation = false;
use a separate config object and pass it into the chart constructor:
var chartOptions = {
responsive:true,
scaleBeginAtZero:false,
barBeginAtOrigin:true
}
var chartInstance = new Chart(ctx).Bar(myChartData, chartOptions);
add a comment |
You can use d3.js for the intended behaviour. Here is a good post regarding that.
Or
You can also follow this article tweaking the plotkit chart to show the downwards negative bar.
To make it work it with chart.js(though not advisable as this is not supported in Chart.js) you can use this github pull and instead of using the global configuration object, i.e. setting:
Chart.defaults.global.responsive = true;
Chart.defaults.global.scaleBeginAtZero = false;
Chart.defaults.global.barBeginAtOrigin = false,
Chart.defaults.global.animation = false;
use a separate config object and pass it into the chart constructor:
var chartOptions = {
responsive:true,
scaleBeginAtZero:false,
barBeginAtOrigin:true
}
var chartInstance = new Chart(ctx).Bar(myChartData, chartOptions);
You can use d3.js for the intended behaviour. Here is a good post regarding that.
Or
You can also follow this article tweaking the plotkit chart to show the downwards negative bar.
To make it work it with chart.js(though not advisable as this is not supported in Chart.js) you can use this github pull and instead of using the global configuration object, i.e. setting:
Chart.defaults.global.responsive = true;
Chart.defaults.global.scaleBeginAtZero = false;
Chart.defaults.global.barBeginAtOrigin = false,
Chart.defaults.global.animation = false;
use a separate config object and pass it into the chart constructor:
var chartOptions = {
responsive:true,
scaleBeginAtZero:false,
barBeginAtOrigin:true
}
var chartInstance = new Chart(ctx).Bar(myChartData, chartOptions);
answered Jun 3 '15 at 7:34
sam100ravsam100rav
2,71921938
2,71921938
add a comment |
add a comment |
I'm using Chart.js version 2.0.2 and this could be achieved using yAxes.min
, and if the chart is empty you could use yAxes.suggestedMax
Example:
options:{
.
.
.
scales{
yAxes:[{
min:0,
//this value will be overridden if the scale is greater than this value
suggestedMax:10
}]
}
add a comment |
I'm using Chart.js version 2.0.2 and this could be achieved using yAxes.min
, and if the chart is empty you could use yAxes.suggestedMax
Example:
options:{
.
.
.
scales{
yAxes:[{
min:0,
//this value will be overridden if the scale is greater than this value
suggestedMax:10
}]
}
add a comment |
I'm using Chart.js version 2.0.2 and this could be achieved using yAxes.min
, and if the chart is empty you could use yAxes.suggestedMax
Example:
options:{
.
.
.
scales{
yAxes:[{
min:0,
//this value will be overridden if the scale is greater than this value
suggestedMax:10
}]
}
I'm using Chart.js version 2.0.2 and this could be achieved using yAxes.min
, and if the chart is empty you could use yAxes.suggestedMax
Example:
options:{
.
.
.
scales{
yAxes:[{
min:0,
//this value will be overridden if the scale is greater than this value
suggestedMax:10
}]
}
answered Apr 25 '17 at 9:48
Mohamed BadrMohamed Badr
1,6882137
1,6882137
add a comment |
add a comment |
public barChartOptions: any = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true}
}]
},
}
add a comment |
public barChartOptions: any = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true}
}]
},
}
add a comment |
public barChartOptions: any = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true}
}]
},
}
public barChartOptions: any = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true}
}]
},
}
answered Dec 6 '17 at 7:07
Reegan SReegan S
211
211
add a comment |
add a comment |
use beginat zero like below:
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
add a comment |
use beginat zero like below:
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
add a comment |
use beginat zero like below:
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
use beginat zero like below:
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
answered Nov 26 '18 at 11:07
RameshRamesh
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30612813%2fchart-js-bar-chart-how-to-chart-bars-from-0%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown