简体   繁体   English

使用JavaScript创建Highchart图

[英]Creating Highchart Graph with JavaScript

I want to create high chart graph . 我想创建高图表图形。

Here is FIDDLE LINK of My code. 这是我的代码的链接

I am giving two values a and b . 我给出两个值a和b。 a for x-axis b for y-axis. a代表x轴b代表y轴。 Problem is that when i gave values of a and b . 问题是当我给出a和b的值时。 when the difference between a and b is less, then no graph appears ie. 当a和b的差较小时,则不会显示任何图形。 a= -9 , b= -9 . a = -9,b = -9。 Otherwise it works 否则它会起作用

$(function () {
    var a, b, x, j;
    a = -9;
    b = -9;

    if (a > b) {
        x = a;
        j = b
    } else {
        x = b;
        j = a
    }


    alert("X is " + x);
    alert("Y is" + j);



    $('#container').highcharts({
        chart: {
            type: 'bar',
            backgroundColor: null
        },
        credits: {
            enabled: false
        },
        tooltip: {
            enabled: false,
        },

        title: {
            text: ''
        },
        xAxis: {
            categories: ["", "", ""],
            //minTickInterval:20000,
        },
        yAxis: {
            min: j - (j * 5 / 100),
            max: x + (x * 5 / 100),

            //min: -50,
            //max: -50,


            //minTickInterval:20000,
            endOnTick: true,
            tickPixelInterval: 340,
            maxPadding: 0.25,
            title: {
                text: ''
            },
            labels: {

                formatter: function () {
                    if (j - (j * 5 / 100) > 1000000) {
                        return Highcharts.numberFormat((this.value) / 1000000, 0, '', ',') + 'M';
                    } else if (j - (j * 5 / 100) > 1000) {
                        return Highcharts.numberFormat((this.value) / 1000, 0, '', ',') + 'K';
                    } else {

                        return Highcharts.numberFormat((this.value), 0, '', ',');


                    }
                },
                x: 6
            }
        },
        legend: {
            backgroundColor: '#FFFFFF',
            reversed: true
        },
        plotOptions: {
            series: {
                stacking: 'normal'
            }
        },
        series: [{
            name: ' ',
            data: [a]
        },

        {
            name: ' ',
            data: [0, b]
        }, ]
    });
});

Here's a working fiddle 这是一个工作的小提琴

Just remove: 只需删除:

min: j-(j*5/100),
max: x+(x*5/100)

from the yAxis: { --- some options --- } 来自yAxis: { --- some options --- }

Also try this with one value positive and other negative for a and b . 还可以使用ab一个positive和另一个negative来尝试此操作。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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