neverbounce / chartjs-plugin-empty-overlay Goto Github PK
View Code? Open in Web Editor NEWChart.js plugin to replace empty plots with a friendly placeholder
License: MIT License
Chart.js plugin to replace empty plots with a friendly placeholder
License: MIT License
Hello!
Please add a screenshot with an example of the overlay to README.md.
Codebase for update plugin to chartjs 3.x
function checkIsEmpty(chart) {
if (chart.config.type == "doughnut") {
var values = chart.data.datasets[0].data;
if (values.length == 0) {
return true;
}
for (i = 0; i < values.length; i++) {
if (values[i] != 0) {
return false;
}
}
return true;
}
return chart.data.datasets[0] == null || chart.data.datasets[0].data.length === 0;
}
Chart.register({
id: 'overlay',
afterDraw: (chart, args, opts) => {
if (checkIsEmpty(chart)) {
var ctx = chart.ctx;
ctx.save();
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.font = "22px Arial";
ctx.fillStyle = "gray";
ctx.fillText('Sem dados', chart.width / 2, chart.height / 2);
ctx.fillStyle = "rgba(0, 0, 0, 0.05)";
ctx.fillRect(0, 0, chart.width, chart.height);
ctx.restore();
}
}
});
I create this source code, inspired into plugin.
The function isChartEmpty throws a type error when validating data that has gaps, or, null values. The error originates during the first filter of isChartEmpty, TypeError: Cannot read property 'X' of null
. The data I'm using is a mix of integers and null values. e.g., [3, 6, null, 12].
Null data means no data, right? Not necessarily. Null is a proper way to represent a gap in the data.
For example, showing run times for a given task. If a point does not have a time value, a value of zero would indicate that the given task took literally no time. Null would indicate that the task did not finish, resulting in a gap in the data.
I'm not sure what Chart.js supported when this plugin was created, but Chart.js currently allows gaps during rendering when a specific property is set. (see Dataset Properties -> spanGaps) Even if spanGaps is not enabled, Chart.js will attempt to skip gaps, effectively merging data around a given gap.
So my bug report-slash-feature request is gap support. If the spanGaps property is set in the Chart.js config (globally or on an individual dataset), allow nulls in the data.
not working with chartjs 3.5
have some errors with 'global' and functions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.