Git Product home page Git Product logo

chartjs-plugin-empty-overlay's Issues

Example screenshot

Hello!
Please add a screenshot with an example of the overlay to README.md.

Sourcecode to update chartjs 3.x

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.

Function isChartEmpty not able to handle nulls in dataset.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.