Search code examples
javascriptamcharts

Calculate valueAxix min automatically


For LineChart

if you have series like these

Line1 
min 0 max 100

it adjust scale automatically and shows the appropriate valueAxis(ex 0 - about 110)

However like this chart

Line2 
min 90 max 110

it also change valueAxis scale (ex 0 - about 120)

However I would like to set scale like (ex 80 - about 120)

I think default amchart4 line chart calculate max of scale not min.

Can I let the amchart4 calculate min scale for value????


Solution

  • I think amchart4 is automatically calculating the min and max for you:

    demo: http://jsfiddle.net/davidliang2008/t09apqdf/

    enter image description here

    Here the data range is between 55 to 102. amchart4 automatically adjusts the y axis to be between 50 to 110, which is pretty smart already!

    If you have to adjust the min and max manually, use extraMin and extraMax property from ValueAxis:https://www.amcharts.com/docs/v4/reference/valueaxis/#extraMin_property

    For example, if your data is range from 90 to 110 and you want the y axis to be from 80 to 120:

    ...
    // (90-80)/90 = 1/9 = 11.1%
    // (120-110)/110 = 1/11 = 9.1%
    "yAxes": [{
        "type": "ValueAxis",
        "extraMax": .091,
        "extraMin": .111
    }],
    ...
    

    enter image description here

    demo: http://jsfiddle.net/davidliang2008/hqxvpefn/

    (Note: my data is generated randomly so it's hard for me to generate the extra range you're looking for. Please take a look at the fiddle links for the setup instead)