Chart.js change vertical position of points - Javascript Chart.js

Javascript examples for Chart.js:Chart Configuration

Description

Chart.js change vertical position of points

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>line chart with ChartJS</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://rawgit.com/nnnick/Chart.js/v1.0.2/Chart.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*w  w w  .  ja va  2s. c om*/
var title = 'LineAlt';
Chart.types.Line.extend({
    name: title,
    buildScale: function() {
        this.options.scaleOverride = true;
        this.options.scaleSteps = 10;
        this.options.scaleStepWidth = this.options.S;
        this.options.scaleStartValue = this.options.target - 5 * this.options.S;
        Chart.types.Line.prototype.buildScale.apply(this, arguments);
        var scale = this.scale;
        var originalCalculateY = scale.calculateY;
        scale.calculateY = function(y) {
            if (y > scale.max)
               return originalCalculateY.apply(this, [scale.max]);
            else if (y < scale.min)
               return originalCalculateY.apply(this, [scale.min]);
            else
                return originalCalculateY.apply(this, [y]);
        }
    },
    draw: function () {
        var chart = this;
        Chart.types.Line.prototype.draw.apply(chart, arguments);
    }
});
var data = {
  labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
  datasets: [
    {
      label: "My First dataset",
      fillColor: "rgba(220,220,220,0.2)",
      strokeColor: "rgba(220,220,220,1)",
      pointColor: "rgba(220,220,220,1)",
      pointStrokeColor: "#fff",
      pointHighlightFill: "#fff",
      pointHighlightStroke: "rgba(220,220,220,1)",
      data: [-50, 5, -90, 181, 156, 55, 40]
    }
  ]
};
var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx).LineAlt(data, {
   S : 10,
  target: 30
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart" height="300" width="800"></canvas>  
   </body>
</html>

Related Tutorials