Search code examples
javascriptamcharts

amCharts - adding padding for a smoothed line serial chart


Can I have amCharts compute a maximum value for the Y axis such as the smoothed line isn't stretched outside the chart div area?

Or can I somehow specify a spacer value, instead of iterating all my values, seeing which is the highest and then setting it myself?

I tried using marginTop, but that simply squeezes the viewing area. enter image description here


Solution

  • The only way to add padding is to change your axis' minimum/maximum. There isn't a direct way to compute an optimal min/max value, but you can set the valueAxis' minMaxMultiplier to pad the automatically calculated min/max values by a small multiplier, i.e. 1.05:

    valueAxes: [{
      // ...
      minMaxMultiplier: 1.05,
      // ...
    }]
    

    Note that the minMaxMultiplier does not affect manually set minimum and maximum values in your valueAxis, so you'll have to remove one or both, depending on how you want that property to affect your axis (you can force your axis to start from 0 if you set the minimum if you don't want minMaxMultiplier creating an unwanted negative axis, for instance).