admin管理员组

文章数量:1402989

I recently add HighChart to my project and I want create chart by it.I wrote this code to create chart for temprature in monthes in some cities:

function CreateChart() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                ype: 'line',
                //type: 'column',
                shadow: true,
                zoomType: 'x',
                style: {
                    fontFamily: 'Tahoma'
                }
            },
            title: {
                text: 'Nima Report',
                x: -20 //center
            },
            labels: {
                items: {
                    style: {
                        fontFamily: 'Tahoma'
                    }
                },
                style: {
                    fontFamily: 'Tahoma'
                }
            },
            subtitle: {
                text: 'Source: --',
                x: -20
            },
            xAxis: {                   
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                labels: {
                    rotation: -45,
                    align: 'right',
                    formatter: function () {
                        return '<span style="font-size: 18px;">' + this.value + '</span>';
                    }
                }
            },
            yAxis: {
                title: {
                    text: 'Temp'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }],
                labels: {
                    align: 'right',
                    formatter: function () {
                        return '<span style="font-size: 18px;font-weight: bold">' + this.value + '</span>';
                    }
                }
            },
            tooltip: {
                crosshairs: [true, true],
                enabled: true,
                style: {
                    fontFamily: "Tahoma",
                    textAlign: "right"
                },
                formatter: function () {
                    return '<b>' + this.series.name + '</b><br/>' +
                    this.x + ': ' + this.y + '°C';
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'top',
                x: -10,
                y: 100,
                borderWidth: 0,
                labelFormatter: function () { return '<span style="font-family: Tahoma">' + this.name + '</span>'; }
            },
            series: [{
                name: 'Tokyo',
                data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
            }, {
                name: 'New York',
                data: [0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
            }, {
                name: 'Berlin',
                data: [0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
            }, {
                name: 'London',
                data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
            }]
        });
    }

the problem is when chart created Y-Axis start value is -25 despite I have not any negative value.I want it start from Zero How I can set it? thanks

I recently add HighChart to my project and I want create chart by it.I wrote this code to create chart for temprature in monthes in some cities:

function CreateChart() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                ype: 'line',
                //type: 'column',
                shadow: true,
                zoomType: 'x',
                style: {
                    fontFamily: 'Tahoma'
                }
            },
            title: {
                text: 'Nima Report',
                x: -20 //center
            },
            labels: {
                items: {
                    style: {
                        fontFamily: 'Tahoma'
                    }
                },
                style: {
                    fontFamily: 'Tahoma'
                }
            },
            subtitle: {
                text: 'Source: --',
                x: -20
            },
            xAxis: {                   
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                labels: {
                    rotation: -45,
                    align: 'right',
                    formatter: function () {
                        return '<span style="font-size: 18px;">' + this.value + '</span>';
                    }
                }
            },
            yAxis: {
                title: {
                    text: 'Temp'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }],
                labels: {
                    align: 'right',
                    formatter: function () {
                        return '<span style="font-size: 18px;font-weight: bold">' + this.value + '</span>';
                    }
                }
            },
            tooltip: {
                crosshairs: [true, true],
                enabled: true,
                style: {
                    fontFamily: "Tahoma",
                    textAlign: "right"
                },
                formatter: function () {
                    return '<b>' + this.series.name + '</b><br/>' +
                    this.x + ': ' + this.y + '°C';
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'top',
                x: -10,
                y: 100,
                borderWidth: 0,
                labelFormatter: function () { return '<span style="font-family: Tahoma">' + this.name + '</span>'; }
            },
            series: [{
                name: 'Tokyo',
                data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
            }, {
                name: 'New York',
                data: [0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
            }, {
                name: 'Berlin',
                data: [0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0]
            }, {
                name: 'London',
                data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
            }]
        });
    }

the problem is when chart created Y-Axis start value is -25 despite I have not any negative value.I want it start from Zero How I can set it? thanks

Share Improve this question asked Feb 11, 2013 at 13:36 DooDooDooDoo 13k70 gold badges191 silver badges318 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

add min to y-axis:

yAxis: {
     title: {
         text: 'Temp'
     },
     plotLines: [{
         value: 0,
         width: 1,
         color: '#808080'
     }],
     labels: {
        align: 'right',
        formatter: function () {
            return '<span style="font-size: 18px;font-weight: bold">' + this.value + '</span>';
        }
     },
      min:0,
},

DEMO

本文标签: javascriptstart value in yaxis in HighChartStack Overflow