Show message that data is empty - Afterdraw #9165
Answered
by
LeeLenaleee
lironesamoun
asked this question in
Q&A
-
Hi, If there is no data available, I would like to show a canva with a simple message saying there is no data available.
With ChartJs 3.X, it does not work anymore. Could you please give me an insight about how to adapt the code or another way to do that ? Thank you |
Beta Was this translation helpful? Give feedback.
Answered by
LeeLenaleee
May 26, 2021
Replies: 1 comment 1 reply
-
You need to give the plugin an id and remove the double chart for your variables function drawNoDataAvailable(canvaID) {
Chart.register({
id: 'noData',
afterDraw: function(chart) {
if (chart.data.datasets.length === 0) {
// No data is present
var ctx = chart.ctx;
var width = chart.width;
var height = chart.height;
chart.clear();
ctx.save();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "35px normal 'Helvetica Nueue'";
ctx.fillStyle = "gray";
ctx.fillText(
"No data Available",
width / 2,
height / 2
);
ctx.restore();
}
}
});
var myChart = new Chart(document.getElementById('chartJSContainer'), {
type: "line",
data: {
labels: [],
datasets: []
}
});
}
drawNoDataAvailable() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
lironesamoun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to give the plugin an id and remove the double chart for your variables