Multiple Date Axes
<h2>Multiple axes</h2> amCharts 4 allows adding multiple axes of any type in any direction. This demo shows comparison of two line series from different periods. [amb href="https://www.amcharts.com/docs/v4/chart-types/xy-chart/#Multiple_axes"]More about multiple axes[/amb] <h2>Synchronized axis grid</h2> The chart can automatically synchronize grid of multiple value axes with a simple setting. [amb href="https://www.amcharts.com/docs/v4/concepts/axes/value-axis/#Synchronizing_grid"]More about grid sync[/amb]
by alcosbarco
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/dataviz.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
/**
* ---------------------------------------
* This demo was created using amCharts 4.
*
* For more information visit:
* https://www.amcharts.com/
*
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
*/
// Themes begin
am4core.useTheme(am4themes_dataviz);
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart
var chart = am4core.create("chartdiv", am4charts.XYChart);
var data = [];
var price1 = 1000, price2 = 1200,price2 = 1400;
var quantity = 30000;
for (var i = 0; i < 360; i++) {
price1 += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 100);
data.push({ date1: new Date(2015, 0, i), price1: price1 });
}
for (var i = 0; i < 360; i++) {
price2 += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 100);
data.push({ date2: new Date(2016, 0, i), price2: price2 });
}
}
for (var i = 0; i < 360; i++) {
price3 += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 100);
data.push({ date3: new Date(2017, 0, i), price3: price3 });
}
chart.data = data;
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.grid.template.location = 0;
dateAxis.renderer.labels.template.fill = am4core.color("#e59165");
var dateAxis2 = chart.xAxes.push(new am4charts.DateAxis());
dateAxis2.renderer.grid.template.location = 0;
dateAxis2.renderer.labels.template.fill = am4core.color("#dfcc64");
var dateAxis3 = chart.xAxes.push(new am4charts.DateAxis());
dateAxis3.renderer.grid.template.location = 0;
dateAxis3.renderer.labels.template.fill = am4core.color("#dfcc64");
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = true;
valueAxis.renderer.labels.template.fill = am4core.color("#e59165");
valueAxis.renderer.minWidth = 60;
var valueAxis2 = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis2.tooltip.disabled = true;
valueAxis2.renderer.labels.template.fill =...