简体   繁体   中英

Highcharts min y-axis value

Is it possible to set a min y-axis value when the series values are the same?

For example:

http://jsfiddle.net/6hyfk/1/

I would like to see 0.00019 as y-axis value.

If i change it to:

series: [{

            data: [0.00019,0.00020,0.00019,0.00019]        
        }]

it looks a lot better.

So the answer largely depends on your data. If for example, you know your values are all positive, setting a yAxis min helps your data display a bit better. You know your data better than I, so I'd look at the yAxis settings and see what you can change to get a better result, but for example, this is a JSFiddle that sets a minimum value:

$(function () {
    $('#container').highcharts({
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            tickLength: 20
        },
        yAxis: {
            min: 0  
        },
        series: [{

            data: [0.00019,0.00019,0.00019,0.00019]        
        }]
    });
});

http://jsfiddle.net/gTG2z/

You can manually set the min and max on the X axis.

yAxis:{
    min: 0,
    max: .001
},

http://jsfiddle.net/6hyfk/2/

If you know what range is in your series, you can set accordingly minRange , so Highcharts will render more ticks as expected. For example: http://jsfiddle.net/Fusher/6hyfk/3/ Good thing about minRange is that it will work also for another values like that: http://jsfiddle.net/Fusher/6hyfk/5/

Probably,you don't need to hardcode min,max values.Do calculation for min and max and set to y Axis as shown below,

$(function () {
    yMin = Math.min.apply(Math,data); // Find Min
    yMax = Math.max.apply(Math,data); //Find Max
    $('#container').highcharts({
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        },
        yAxis: {
            min: yMin,
            max: yMax 
        },
        series: [{

            data: data //Array of values        
        }]
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM