JavaScript TypeScript / ES6 ...
<style >
#chartdiv {
width : 100% ;
height : 350px ;
}
</style >
<script src ="https://cdn.amcharts.com/lib/4/core.js" > </script >
<script src ="https://cdn.amcharts.com/lib/4/charts.js" > </script >
<script src ="https://cdn.amcharts.com/lib/4/themes/animated.js" > </script >
<script >
am4core.ready (function ( ) {
am4core.useTheme (am4themes_animated);
var chart = am4core.create ("chartdiv" , am4charts.XYChart );
chart.paddingRight = 25 ;
chart.data = [{
"x" : 0 ,
"y" : 400 ,
"color" : chart.colors .getIndex (0 )
}, {
"x" : 14 ,
"y" : 500 ,
"color" : chart.colors .getIndex (1 )
}, {
"x" : 22 ,
"y" : 550 ,
"color" : chart.colors .getIndex (0 )
}, {
"x" : 26 ,
"y" : 750 ,
"color" : chart.colors .getIndex (0 )
}, {
"x" : 29 ,
"y" : 930 ,
"color" : chart.colors .getIndex (1 )
}, {
"x" : 43 ,
"y" : 1020 ,
"color" : chart.colors .getIndex (0 )
}, {
"x" : 50 ,
"y" : 1200 ,
"color" : chart.colors .getIndex (1 )
}];
var xAxis = chart.xAxes .push (new am4charts.ValueAxis ());
xAxis.renderer .grid .template .disabled = true ;
xAxis.renderer .labels .template .disabled = true ;
xAxis.numberFormatter = new am4core.NumberFormatter ();
xAxis.numberFormatter .numberFormat = "#,###'km'" ;
xAxis.min = 0 ;
xAxis.max = 50 ;
xAxis.strictMinMax = true ;
var yAxis = chart.yAxes .push (new am4charts.ValueAxis ());
yAxis.numberFormatter = new am4core.NumberFormatter ();
yAxis.numberFormatter .numberFormat = "#,###'m'" ;
yAxis.min = 400 ;
yAxis.max = 1400 ;
yAxis.strictMinMax = true ;
var series = chart.series .push (new am4charts.LineSeries ());
series.dataFields .valueX = "x" ;
series.dataFields .valueY = "y" ;
series.name = name;
series.tooltipText = "{valueX}km: [bold]{valueY}m[/]" ;
series.strokeWidth = 0 ;
series.fillOpacity = 0.8 ;
series.propertyFields .fill = "color" ;
for (var i = 0 ; i < chart.data .length ; i++) {
var value = chart.data [i].x ;
var range = xAxis.axisRanges .create ();
range.value = value;
range.label .text = value + "km" ;
}
chart.cursor = new am4charts.XYCursor ();
chart.cursor .snapToSeries = series;
});
</script >
<div id ="chartdiv" > </div >
import * as am4core from "@amcharts/amcharts4/core" ;
import * as am4charts from "@amcharts/amcharts4/charts" ;
import am4themes_animated from "@amcharts/amcharts4/themes/animated" ;
am4core.useTheme (am4themes_animated);
let chart = am4core.create ("chartdiv" , am4charts.XYChart );
chart.paddingRight = 25 ;
chart.data = [{
"x" : 0 ,
"y" : 400 ,
"color" : chart.colors .getIndex (0 )
}, {
"x" : 14 ,
"y" : 500 ,
"color" : chart.colors .getIndex (1 )
}, {
"x" : 22 ,
"y" : 550 ,
"color" : chart.colors .getIndex (0 )
}, {
"x" : 26 ,
"y" : 750 ,
"color" : chart.colors .getIndex (0 )
}, {
"x" : 29 ,
"y" : 930 ,
"color" : chart.colors .getIndex (1 )
}, {
"x" : 43 ,
"y" : 1020 ,
"color" : chart.colors .getIndex (0 )
}, {
"x" : 50 ,
"y" : 1200 ,
"color" : chart.colors .getIndex (1 )
}];
let xAxis = chart.xAxes .push (new am4charts.ValueAxis ());
xAxis.renderer .grid .template .disabled = true ;
xAxis.renderer .labels .template .disabled = true ;
xAxis.numberFormatter = new am4core.NumberFormatter ();
xAxis.numberFormatter .numberFormat = "#,###'km'" ;
xAxis.min = 0 ;
xAxis.max = 50 ;
xAxis.strictMinMax = true ;
let yAxis = chart.yAxes .push (new am4charts.ValueAxis ());
yAxis.numberFormatter = new am4core.NumberFormatter ();
yAxis.numberFormatter .numberFormat = "#,###'m'" ;
yAxis.min = 400 ;
yAxis.max = 1400 ;
yAxis.strictMinMax = true ;
let series = chart.series .push (new am4charts.LineSeries ());
series.dataFields .valueX = "x" ;
series.dataFields .valueY = "y" ;
series.name = name;
series.tooltipText = "{valueX}km: [bold]{valueY}m[/]" ;
series.strokeWidth = 0 ;
series.fillOpacity = 0.8 ;
series.propertyFields .fill = "color" ;
for (var i = 0 ; i < chart.data .length ; i++) {
let value = chart.data [i].x ;
let range = xAxis.axisRanges .create ();
range.value = value;
range.label .text = value + "km" ;
}
chart.cursor = new am4charts.XYCursor ();
chart.cursor .snapToSeries = series;