Guest User

Untitled

a guest
Jul 31st, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Chart.helpers.extend(Chart.controllers.line.prototype, {
  2.             draw: function () {
  3.                 originalLineDraw.apply(this, arguments);
  4.  
  5.                 chart = this.chart;
  6.                 ctx = chart.chart.ctx;
  7.  
  8.                 arr = chart.config.data.lineAtIndexGrouped;
  9.  
  10.                 // console.log('outside', arr);
  11.                 if (arr) {
  12.  
  13.                     xaxis = chart.scales['x-axis-0'];
  14.                     yaxis = chart.scales['y-axis-0'];
  15.  
  16.                     for (var index in arr) {
  17.  
  18.                         ctx.moveTo(xaxis.getPixelForValue(undefined, index), yaxis.top);
  19.                         ctx.strokeStyle = '#ff0000';
  20.                         ctx.lineTo(xaxis.getPixelForValue(undefined, index), yaxis.bottom);
  21.                         ctx.stroke();
  22.                         ctx.restore();
  23.                     }
  24.                 }
  25.             },
  26.             execute: function() {
  27.                 ctx.save();
  28.                 ctx.beginPath();
  29.                 ctx.font = "12px Arial";
  30.                 ctx.fillStyle = '#000';
  31.                 chartElement.mousemove(function(evt) {
  32.                     for (var index in arr) {
  33.                         if (evt.clientX - $(this).offset().left > xaxis.getPixelForValue(undefined, index) - 5
  34.                             && evt.clientX - $(this).offset().left < xaxis.getPixelForValue(undefined, index) + 5) {
  35.                             var counter = 0;
  36.                             arr[index].labels.forEach(function (el) {
  37.                                 ctx.fillText(el, xaxis.getPixelForValue(undefined, index), yaxis.top + 20 + counter * 12);
  38.                                 counter++;
  39.                             });
  40.                         } else {
  41.  
  42.                         }
  43.                     }
  44.                 });
  45.             }
  46.         });
Advertisement
Add Comment
Please, Sign In to add comment