Skip to content

Sourcecode to update chartjs 3.x #7

@FelipeWielewski

Description

@FelipeWielewski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions