chartjs default background color to columns
Hello how i can set default background color to dataset columns? like on image.
The gray part of columns. So every columns will have gray background color from 0 to max value.

Here is the code of my data chart. I look the examples on chart.js site but there i can't find anythin about this situation
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
]
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
);
charts chart.js chartjs-2.6.0
add a comment |
Hello how i can set default background color to dataset columns? like on image.
The gray part of columns. So every columns will have gray background color from 0 to max value.

Here is the code of my data chart. I look the examples on chart.js site but there i can't find anythin about this situation
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
]
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
);
charts chart.js chartjs-2.6.0
@WhiteHat hello, my question is updated. Thanks
– user3348410
Nov 14 '18 at 6:00
add a comment |
Hello how i can set default background color to dataset columns? like on image.
The gray part of columns. So every columns will have gray background color from 0 to max value.

Here is the code of my data chart. I look the examples on chart.js site but there i can't find anythin about this situation
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
]
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
);
charts chart.js chartjs-2.6.0
Hello how i can set default background color to dataset columns? like on image.
The gray part of columns. So every columns will have gray background color from 0 to max value.

Here is the code of my data chart. I look the examples on chart.js site but there i can't find anythin about this situation
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
]
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
);
charts chart.js chartjs-2.6.0
charts chart.js chartjs-2.6.0
edited Nov 14 '18 at 5:59
user3348410
asked Nov 13 '18 at 13:55
user3348410user3348410
202415
202415
@WhiteHat hello, my question is updated. Thanks
– user3348410
Nov 14 '18 at 6:00
add a comment |
@WhiteHat hello, my question is updated. Thanks
– user3348410
Nov 14 '18 at 6:00
@WhiteHat hello, my question is updated. Thanks
– user3348410
Nov 14 '18 at 6:00
@WhiteHat hello, my question is updated. Thanks
– user3348410
Nov 14 '18 at 6:00
add a comment |
1 Answer
1
active
oldest
votes
an option doesn't exist for column background color.
a third series will need to be added to represent the background.
which can easily be done by subtracting the original values from the max value.
the tooltip for the background series can be removed by using the filter option.
see following working snippet...
$(document).ready(function()
// original datasets
var chartData = [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
];
// max value - background dataset
var maxValue = 200;
var maxData =
label: 'Max',
data: ,
backgroundColor: '#cccccc'
;
// subtract each dataset value from max value
chartData.forEach(function (dataset)
dataset.data.forEach(function (value, index)
if (maxData.data.length <= index)
maxData.data.push(maxValue);
maxData.data[index] -= value;
);
);
// add background dataset
chartData.push(maxData);
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: chartData // <-- modified dataset
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
,
// remove tooltip for background dataset
tooltips:
filter: function (tooltipItem, data)
return (tooltipItem.datasetIndex < (chartData.length - 1));
,
);
);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="data"></canvas>
Thanks so much its worked perfectly
– user3348410
Nov 14 '18 at 13:32
add a comment |
Your Answer
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%2f53282620%2fchartjs-default-background-color-to-columns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
an option doesn't exist for column background color.
a third series will need to be added to represent the background.
which can easily be done by subtracting the original values from the max value.
the tooltip for the background series can be removed by using the filter option.
see following working snippet...
$(document).ready(function()
// original datasets
var chartData = [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
];
// max value - background dataset
var maxValue = 200;
var maxData =
label: 'Max',
data: ,
backgroundColor: '#cccccc'
;
// subtract each dataset value from max value
chartData.forEach(function (dataset)
dataset.data.forEach(function (value, index)
if (maxData.data.length <= index)
maxData.data.push(maxValue);
maxData.data[index] -= value;
);
);
// add background dataset
chartData.push(maxData);
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: chartData // <-- modified dataset
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
,
// remove tooltip for background dataset
tooltips:
filter: function (tooltipItem, data)
return (tooltipItem.datasetIndex < (chartData.length - 1));
,
);
);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="data"></canvas>
Thanks so much its worked perfectly
– user3348410
Nov 14 '18 at 13:32
add a comment |
an option doesn't exist for column background color.
a third series will need to be added to represent the background.
which can easily be done by subtracting the original values from the max value.
the tooltip for the background series can be removed by using the filter option.
see following working snippet...
$(document).ready(function()
// original datasets
var chartData = [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
];
// max value - background dataset
var maxValue = 200;
var maxData =
label: 'Max',
data: ,
backgroundColor: '#cccccc'
;
// subtract each dataset value from max value
chartData.forEach(function (dataset)
dataset.data.forEach(function (value, index)
if (maxData.data.length <= index)
maxData.data.push(maxValue);
maxData.data[index] -= value;
);
);
// add background dataset
chartData.push(maxData);
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: chartData // <-- modified dataset
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
,
// remove tooltip for background dataset
tooltips:
filter: function (tooltipItem, data)
return (tooltipItem.datasetIndex < (chartData.length - 1));
,
);
);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="data"></canvas>
Thanks so much its worked perfectly
– user3348410
Nov 14 '18 at 13:32
add a comment |
an option doesn't exist for column background color.
a third series will need to be added to represent the background.
which can easily be done by subtracting the original values from the max value.
the tooltip for the background series can be removed by using the filter option.
see following working snippet...
$(document).ready(function()
// original datasets
var chartData = [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
];
// max value - background dataset
var maxValue = 200;
var maxData =
label: 'Max',
data: ,
backgroundColor: '#cccccc'
;
// subtract each dataset value from max value
chartData.forEach(function (dataset)
dataset.data.forEach(function (value, index)
if (maxData.data.length <= index)
maxData.data.push(maxValue);
maxData.data[index] -= value;
);
);
// add background dataset
chartData.push(maxData);
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: chartData // <-- modified dataset
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
,
// remove tooltip for background dataset
tooltips:
filter: function (tooltipItem, data)
return (tooltipItem.datasetIndex < (chartData.length - 1));
,
);
);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="data"></canvas>an option doesn't exist for column background color.
a third series will need to be added to represent the background.
which can easily be done by subtracting the original values from the max value.
the tooltip for the background series can be removed by using the filter option.
see following working snippet...
$(document).ready(function()
// original datasets
var chartData = [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
];
// max value - background dataset
var maxValue = 200;
var maxData =
label: 'Max',
data: ,
backgroundColor: '#cccccc'
;
// subtract each dataset value from max value
chartData.forEach(function (dataset)
dataset.data.forEach(function (value, index)
if (maxData.data.length <= index)
maxData.data.push(maxValue);
maxData.data[index] -= value;
);
);
// add background dataset
chartData.push(maxData);
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: chartData // <-- modified dataset
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
,
// remove tooltip for background dataset
tooltips:
filter: function (tooltipItem, data)
return (tooltipItem.datasetIndex < (chartData.length - 1));
,
);
);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="data"></canvas>$(document).ready(function()
// original datasets
var chartData = [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
];
// max value - background dataset
var maxValue = 200;
var maxData =
label: 'Max',
data: ,
backgroundColor: '#cccccc'
;
// subtract each dataset value from max value
chartData.forEach(function (dataset)
dataset.data.forEach(function (value, index)
if (maxData.data.length <= index)
maxData.data.push(maxValue);
maxData.data[index] -= value;
);
);
// add background dataset
chartData.push(maxData);
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: chartData // <-- modified dataset
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
,
// remove tooltip for background dataset
tooltips:
filter: function (tooltipItem, data)
return (tooltipItem.datasetIndex < (chartData.length - 1));
,
);
);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="data"></canvas>$(document).ready(function()
// original datasets
var chartData = [
label: 'Capacity',
data: [20.7, 10, 40, 2, 100, 43, 34],
backgroundColor: '#43d100'
,
label: 'Confirmed',
data: [11.4, 100, 20, 42, 10, 20, 65],
backgroundColor: '#dc1f1f'
];
// max value - background dataset
var maxValue = 200;
var maxData =
label: 'Max',
data: ,
backgroundColor: '#cccccc'
;
// subtract each dataset value from max value
chartData.forEach(function (dataset)
dataset.data.forEach(function (value, index)
if (maxData.data.length <= index)
maxData.data.push(maxValue);
maxData.data[index] -= value;
);
);
// add background dataset
chartData.push(maxData);
var ctx = document.getElementById("data");
var myChart = new Chart(ctx,
type: 'bar',
data:
labels: ['Today', '12 Th', '13 Fr', '14 St', '15 Sn', '16 Mn', '17 Tu'],
datasets: chartData // <-- modified dataset
,
options:
legend:
display: false
,
layout:
borderWidth: 0
,
scales:
xAxes: [
stacked: true,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
],
yAxes: [
stacked: true,
ticks:
beginAtZero: true,
display: false,
max: 200,
fill: "#07C"
,
gridLines:
display: false,
borderWidth: 0,
drawBorder: false
]
,
// remove tooltip for background dataset
tooltips:
filter: function (tooltipItem, data)
return (tooltipItem.datasetIndex < (chartData.length - 1));
,
);
);<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script>
<canvas id="data"></canvas>answered Nov 14 '18 at 12:50
WhiteHatWhiteHat
36.8k61576
36.8k61576
Thanks so much its worked perfectly
– user3348410
Nov 14 '18 at 13:32
add a comment |
Thanks so much its worked perfectly
– user3348410
Nov 14 '18 at 13:32
Thanks so much its worked perfectly
– user3348410
Nov 14 '18 at 13:32
Thanks so much its worked perfectly
– user3348410
Nov 14 '18 at 13:32
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%2f53282620%2fchartjs-default-background-color-to-columns%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
@WhiteHat hello, my question is updated. Thanks
– user3348410
Nov 14 '18 at 6:00