Adding Custom Breaks in axisX using addTo Method - CanvasJS JavaScript Charts

Adding Custom Breaks in axisX using addTo Method - CanvasJS JavaScript Charts

by canvasjs

HTML

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>

JavaScript

var chart = new CanvasJS.Chart("chartContainer",{
  title: {
    text: "Custom Break on Axis X"
  },
  axisY: {
    title: "Global Population (in mm)"
  },
  axisX: {
    title: "Time",
    labelAutoFit: false,
    valueFormatString: "###0.##",
    scaleBreaks: {}
  },
  data: [{
    type: "line",
    dataPoints: [
      { x: -50, label: "50 BC", y: 300 },
      { x: 0, y: 371 },
      { x: 1750, y: 950 },
      { x: 1800, y: 1200 },
      { x: 1850, y: 1500 },
      { x: 1900, y: 1900 },
      { x: 1950, y: 2600 },
      { x: 1975, y: 4100 },
      { x: 2000, y: 6000 }
    ]
  }]
});
chart.render();

chart.axisX[0].scaleBreaks.addTo("customBreaks", {
  startValue: 50, 
  endValue: 1700 
});