3

So I have a plugin that does a custom drawing after the event "afterDraw". I'd like to be able hide the drawing by overriding the legend box onClick method and animating the hiding part using the charts default animation options. Is there any function I can call using the id for my plugin? Thanks in advance.

Example of my my code: The addLabel part just does the drawing, no more than that.

plugins: [{ 
            id : 'drawLabelPlugin',
            afterDraw: function(chart, args, options) {
                var chartInstance = chart;
                ctx = chartInstance.ctx; 
                chartInstance.data.datasets.forEach(function (dataset, i) { //For each type of chart                    
                    var defaultFont = '11.5px -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
                    ctx.textAlign = 'start';
                    ctx.textBaseline = 'bottom';
                    meta = chartInstance.getDatasetMeta(i);
                   
                    if(meta.label == ma1title/* && !meta.hidden*/){            
                        var last = meta.data.length - 1; 
                        addLabel(defaultFont, 12.5, '#2c6288', '#ffffff', '#2c6288', 1.3, meta.data[last].x, meta.data[last].y, dataset.data[last].y, 7.65, 6.1, false);

                    }
              }


uminder
  • 23,831
  • 5
  • 37
  • 72
azidninja
  • 41
  • 2
  • Could you share what you've done so far by posting a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? – It'sNotMe Jan 09 '21 at 01:52
  • Edited it, this is the plugin basically. So far I havent edited the onClick function of the legend. It's the exact same one found at the bottom of the one found on: https://www.chartjs.org/docs/master/configuration/legend – azidninja Jan 09 '21 at 02:00

0 Answers0