amcharts3 icon indicating copy to clipboard operation
amcharts3 copied to clipboard

Line graph offset from category axis

Open igoriok1994 opened this issue 6 years ago • 4 comments

Hi. Maybe someone know how to offset graph from category axis? image When value = 0, line is invincible. O maybe there is a way to offset value axis or something like that...

image

igoriok1994 avatar Oct 16 '18 08:10 igoriok1994

Hi there,

Have you tried setting a minimum on your valueAxis? (You might need to enforce this setting by adding strictMinMax: true.

"valueAxes": [{
  "minimum": -0.1,
  "strictMinMax": true
}]

Hope this helps!

Docs: https://docs.amcharts.com/3/javascriptcharts/ValueAxis#minimum https://docs.amcharts.com/3/javascriptcharts/ValueAxis#strictMinMax

RobbiesCode avatar Oct 16 '18 11:10 RobbiesCode

Hi,

Thanks for suggestion I haven't tried it yet, but I will. But what if I don't know max and min values (another case)? Eg. I can have 100k amount of data. Is there any way to set offset from bottom (value axis, graph)?

igoriok1994 avatar Oct 16 '18 12:10 igoriok1994

That would require some extra logic. There are no settings that would do what you described, but you can set the minimum (or maximum) dynamically, based on your data, inside addInitHandler. This method is used before the chart is initialized.

Here is an example for a simple column chart:

AmCharts.addInitHandler(function(chart) {

  // find data minimum & maximum:
  var min = chart.dataProvider[0].value;
  var max = chart.dataProvider[0].value;
  for (var i in chart.dataProvider) {
    if (chart.dataProvider[i].value > max) {
      max = chart.dataProvider[i].value;
    }
    if(chart.dataProvider[i].value < min){
      min = chart.dataProvider[i].value;
    }
  }

  min -= 10; // subtract an arbitrary offset 

  // set axes max based on value above:
  chart.valueAxes[0].minimum = min;
  // chart.valueAxes[0].maximum = max;
  chart.valueAxes[0].strictMinMax = true;
});

RobbiesCode avatar Oct 16 '18 12:10 RobbiesCode

Yes, looks like I have to add min/max logic to my pivot. Thanks :)

igoriok1994 avatar Oct 16 '18 13:10 igoriok1994