Thrombox Chartjs v2

I would like to use a string string for my line chart. But every solution I found only works with chartjs v1.

Is this their solution for the newest?

thats I developed with chartjs v1, but as I said, I did not find a way to do this with version 2.

jsfiddle

Chart.types.Line.extend({
  name: "LineAlt",
  initialize: function () {
    Chart.types.Line.prototype.initialize.apply(this, arguments);

    var ctx = this.chart.ctx;
    var originalStroke = ctx.stroke;
    ctx.stroke = function () {
      ctx.save();
      ctx.shadowColor = '#E56590';
      ctx.shadowBlur = 10;
      ctx.shadowOffsetX = 0;
      ctx.shadowOffsetY = 4;
      originalStroke.apply(this, arguments)
      ctx.restore();
    }
  }
});

var data = {
  labels: ["January", "February", "March", "April", "May", "June", "July"],
  datasets: [
    {
      label: "My First dataset",
      fillColor: "#fff",
      strokeColor: "#ffb88c",
      pointColor: "#fff",
      pointStrokeColor: "#ffb88c",
      pointHighlightFill: "#ffb88c",
      pointHighlightStroke: "#fff",
      data: [65, 59, 80, 81, 56, 55, 40]
    }
  ]
};


var ctx = document.getElementById("canvas").getContext("2d");
var myChart = new Chart(ctx).LineAlt(data, {
  datasetFill: false
});

Html:

<canvas id="canvas" width="600" height="300" style="background-color:#fff"></canvas>
+6
source share
1 answer

Yes!

You can perform the same shadow shadow effect for a line chart with ChartJS v2 as follows:

let draw = Chart.controllers.line.prototype.draw;
Chart.controllers.line = Chart.controllers.line.extend({
    draw: function() {
        draw.apply(this, arguments);
        let ctx = this.chart.chart.ctx;
        let _stroke = ctx.stroke;
        ctx.stroke = function() {
            ctx.save();
            ctx.shadowColor = '#E56590';
            ctx.shadowBlur = 10;
            ctx.shadowOffsetX = 0;
            ctx.shadowOffsetY = 4;
            _stroke.apply(this, arguments)
            ctx.restore();
        }
    }
});

let ctx = document.getElementById("canvas").getContext('2d');
let myChart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: ["January", "February", "March", "April", "May", "June", "July"],
        datasets: [{
            label: "My First dataset",
            data: [65, 59, 80, 81, 56, 55, 40],
            borderColor: '#ffb88c',
            pointBackgroundColor: "#fff",
            pointBorderColor: "#ffb88c",
            pointHoverBackgroundColor: "#ffb88c",
            pointHoverBorderColor: "#fff",
            pointRadius: 4,
            pointHoverRadius: 4,
            fill: false
        }]
    }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="canvas" width="600" height="300" style="background-color:#fff"></canvas>
Run codeHide result
+5
source

Source: https://habr.com/ru/post/1016574/


All Articles