Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AmCharts remove gap at start of serialChart

I am trying AmCharts for the first time and having trouble with one small thing. I created a graph using the following javascript:

   dayGraph = new AmCharts.AmGraph();
   dayGraph.valueField = "value";
   dayGraph.type = "line";
   dayGraph.balloonText = "<b>[[value]]</b>";
   dayGraph.connect = false;
   dayGraph.lineThickness = 2;
   dayGraph.lineColor = "#8B0000";
   dayGraph.fillColor = "#8B0000";
   dayGraph.fillAlphas = 0.5;

   chartCursor = new AmCharts.ChartCursor();

   energyChart = new AmCharts.AmSerialChart();
   energyChart.categoryField = "time";
/*   energyChart.startDuration = 1;*/
   energyChart.addGraph(dayGraph);
   energyChart.categoryAxis.parseDates = true;
   energyChart.categoryAxis.minPeriod = "mm";
   energyChart.chartCursor = chartCursor;
   energyChart.categoryAxis.equalSpacing = true;

It seems to work well, but I can't seem to find a way to remove the gap at the start of the graph (before the 00:00 value). The first data point is exactly at 00:00, so I would expect this point to sit on the vertical axis. Instead, there is a small gap. See the images below for how it currently is, and how I want it to look.

The current graph looks like this:

Current

I want it to look like this:

Desired

like image 848
Joe Avatar asked Jan 26 '26 01:01

Joe


1 Answers

Each serial chart already has categoryAxis property with a reference to CategoryAxis object. So you can just set it's startOnAxis property to true:

energyChart.categoryAxis.startOnAxis = true;

or, if you need to instantiate your own:

energyChart.categoryAxis = new AmCharts.CategoryAxis();
energyChart.categoryAxis.startOnAxis = true;

Whatever floats your boat.

Also, it's worth noting, that for date-based category axes, startOnAxis will work only if equalSpacing is set to true.

like image 95
J. Titus Avatar answered Jan 27 '26 15:01

J. Titus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!