[Chartjs]-Can't trigger beforeDraw with Vue-Chartjs (or any other plugins)

3πŸ‘

Plugins can optionally be registered globally through Chart.plugins.register. You can register any of the hooks provided by the Plugin Core API and provide your custom code. The afterDraw hook for example would have to be registered as follows:

Chart.plugins.register({
  afterDraw: chart => {
    // your code  
  }
});

2πŸ‘

    mounted () {
    this.addPlugin({
        id: 'my-plugin',
        afterDraw: function (chart) {
            var ctx = chart.ctx;
            ctx.font = "bold 20px FiraGO";
            ctx.fillStyle = "red";
            ctx.textAlign = "center";
            ctx.fillText("αƒšαƒ˜αƒ‘αƒ”αƒ αƒαƒšαƒ£αƒ αƒ˜", chart.width/2, chart.height - 25);
            ctx.font = "bold 20px FiraGO";
            ctx.fillStyle = "red";
            ctx.textAlign = "center";
            ctx.fillText("αƒαƒ•αƒ’αƒαƒ αƒ˜αƒ’αƒαƒ αƒ£αƒšαƒ˜", chart.width/2, 25);
            ctx.font = "bold 20px FiraGO";
            ctx.fillStyle = "red";
            ctx.textAlign = "center";
            ctx.rotate(Math.PI/2);
            ctx.fillText("αƒ’αƒ”αƒ’αƒ›αƒ˜αƒ£αƒ αƒ˜ αƒ”αƒ™αƒαƒœαƒαƒ›αƒ˜αƒ™αƒ", chart.width/(-2), 25);
            // ctx.save();
            ctx.fillText("αƒ—αƒαƒ•αƒ˜αƒ‘αƒ£αƒ€αƒαƒšαƒ˜ αƒ”αƒ™αƒαƒœαƒαƒ›αƒ˜αƒ™αƒ", chart.width/(-2), chart.height - 25);
            // ctx.save();
            // ctx.rotate(Math.PI/(-2))
            // ctx.save();
        }
    });
    this.renderChart(this.chartdata, {
            scales: {
                xAxes: [{
                    ticks: {
                        max: 100,
                        min: -100
                    },
                    type: 'linear',
                }],
                yAxes: [{
                    display: true,
                    type: 'linear',
                    ticks: {
                        max: 100,
                        min: -100
                    }
                }]
            },
            elements: {
                point: {
                    pointStyle: 'circle',
                    radius: 16,
                    backgroundColor: "#dc005a"
                }
            },
            layout: {
                padding: {
                    left: 50,
                    right: 50,
                    top: 50,
                    bottom: 50
                }
            },
    });
}

Leave a comment