Normally, a Line series with fill enabled, will fill any space between itself and a horizontal “zero line”. This tutorial will explore, how we can tame it to our specific needs.
Consider this basic chart. It’s a two-Value axis chart with a Line series, wiggling around zero values - both horizontally and vertically.
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
//var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
//categoryAxis.dataFields.category = "category";
//categoryAxis.renderer.grid.template.location = 0;
//categoryAxis.renderer.minGridDistance = 30;
var xAxis = chart . xAxes . push ( new am4charts . ValueAxis ());
xAxis . strictMinMax = true ;
var yAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
yAxis . strictMinMax = true ;
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = " y " ;
series . dataFields . valueX = " x " ;
series . fillOpacity = 0.3 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Controlling line series fill (1) controlling-line-series-fill-1
As you can see, the fill goes all the way to the zero line. That’s the default behavior.
In fact, the line fill does not extend to zero line. It rather extends to “base value”, which, coincidentally is zero.
Let’s say we don’t want the fill to go up and down, but rather fill all the way down.
To do that, we need to set Y axis’ baseValue to some low number:
Let’s see how our chart has changed.
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
//var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
//categoryAxis.dataFields.category = "category";
//categoryAxis.renderer.grid.template.location = 0;
//categoryAxis.renderer.minGridDistance = 30;
var xAxis = chart . xAxes . push ( new am4charts . ValueAxis ());
xAxis . strictMinMax = true ;
var yAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
yAxis . strictMinMax = true ;
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = " y " ;
series . dataFields . valueX = " x " ;
series . fillOpacity = 0.3 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Controlling line series fill (2) controlling-line-series-fill-2
Should we want to fill upwards, we’d set it to some big value, instead.
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
//var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
//categoryAxis.dataFields.category = "category";
//categoryAxis.renderer.grid.template.location = 0;
//categoryAxis.renderer.minGridDistance = 30;
var xAxis = chart . xAxes . push ( new am4charts . ValueAxis ());
xAxis . strictMinMax = true ;
var yAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
yAxis . strictMinMax = true ;
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = " y " ;
series . dataFields . valueX = " x " ;
series . fillOpacity = 0.3 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Controlling line series fill (3) controlling-line-series-fill-3
Now, let’s say we want the fill to happen sideways, instead of vertically.
We can achieve that by changing baseAxis of our series. All we have to do is to tell that our Y axis is now the “base axis”.
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
//var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
//categoryAxis.dataFields.category = "category";
//categoryAxis.renderer.grid.template.location = 0;
//categoryAxis.renderer.minGridDistance = 30;
var xAxis = chart . xAxes . push ( new am4charts . ValueAxis ());
xAxis . strictMinMax = true ;
var yAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
yAxis . strictMinMax = true ;
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = " y " ;
series . dataFields . valueX = " x " ;
series . fillOpacity = 0.3 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Controlling line series fill (4) controlling-line-series-fill-4
Since we changed base axis to a vertical one, the vertical zero line is the target to fill now.
We can use the same baseValue to implement fill span.
Run * --------------------------------------------------------
* This demo was created using amCharts V4 preview release.
* V4 is the latest installement in amCharts data viz
* library family, to be released in the first half of
* For more information and documentation visit:
* https://www.amcharts.com/docs/v4/
* --------------------------------------------------------
am4core . useTheme ( am4themes_animated );
var chart = am4core . create ( " chartdiv " , am4charts . XYChart );
//var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
//categoryAxis.dataFields.category = "category";
//categoryAxis.renderer.grid.template.location = 0;
//categoryAxis.renderer.minGridDistance = 30;
var xAxis = chart . xAxes . push ( new am4charts . ValueAxis ());
xAxis . strictMinMax = true ;
var yAxis = chart . yAxes . push ( new am4charts . ValueAxis ());
yAxis . strictMinMax = true ;
var series = chart . series . push ( new am4charts . LineSeries ());
series . dataFields . valueY = " y " ;
series . dataFields . valueX = " x " ;
series . fillOpacity = 0.3 ;
< div id = " chartdiv " ></ div >
-apple-system , BlinkMacSystemFont, " Segoe UI " , Roboto, Helvetica , Arial , sans-serif ,
" Apple Color Emoji " , " Segoe UI Emoji " , " Segoe UI Symbol " ;
Controlling line series fill (5) controlling-line-series-fill-5