Zoomable Value Axis

<h2>Zoomable in any direction</h2> The chart can support zooming in any direction. For that it has two properties: <code>scrollbarX</code> and <code>scrollbarY</code>. Both can be set with an instance of a Scrollbar, and configured individually. [amcharts2_button href="<a href="https://www.amcharts.com/docs/v4/concepts/axes/#Zooming">https://www.amcharts.com/docs/v4/concepts/chart-cursor/</a>"]More about zooming of axes[/amcharts2_button] <h2>Zooming with cursor</h2> Chart cursor can be set up to perform a plethora of tasks. In this demo we have set cursor's <code>behavior</code> to <code>"zoomY"</code> which means that cursor will select and zoom vertically. [amcharts2_button href="https://www.amcharts.com/docs/v4/concepts/chart-cursor/"]More about chart cursor[/amcharts2_button]

by Rogério Saraceni

HTML

<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/animated.js"></script>
<div id="chartdiv"></div>

CSS

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

#chartdiv {
  width: 100%;
  height: 500px;
}

JavaScript

am4core.ready(function() {
		// Themes begin
		am4core.useTheme(am4themes_animated);
		// Themes end

		// Create chart instance
		var chart = am4core.create("chartdiv", am4charts.XYChart);

		chart.autoMargins = false;
		chart.marginRight = 0;
    chart.marginLeft = 0;
    chart.marginBottom = 0;
    chart.marginTop = 0;
		

		var title = chart.titles.create();
		title.text = "CAPEX";
		title.fontSize = 16;
		title.fontWeight = 400;
		title.textAlign = "middle";
		title.fill = "#777777";

		// Add data
		chart.data = [
			{
			  "date": "2013-01-26",
			  "value": 87
			}, {
			  "date": "2013-01-27",
			  "value": 84
			}, {
			  "date": "2013-01-28",
			  "value": 83
			}, {
			  "date": "2013-01-29",
			  "value": 84
			}, {
			  "date": "2013-01-30",
			  "value": 81
			} 
		];

		// Create axes
		var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
		dateAxis.renderer.minGridDistance = 0;
		dateAxis.renderer.labels.template.disabled = true;
		dateAxis.renderer.grid.template.disabled = true;
   

		var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
		valueAxis.renderer.labels.template.disabled = true;
		valueAxis.renderer.grid.template.disabled = true;
		valueAxis.renderer.inside = true;

		// Create series
		var series = chart.series.push(new am4charts.LineSeries());
		series.dataFields.valueY = "value";
		series.dataFields.dateX = "date";
		series.strokeWidth = 3;
		series.fillOpacity = 0.5;

		// Add cursor
		chart.cursor = new am4charts.XYCursor();
		chart.cursor.behavior = "zoomY";
		chart.cursor.lineX.disabled = true;
	});