javascript - 使用 JavaScript 创建 Highchart 图

标签 javascript jquery html css

我想创建高图表。

这是 FIDDLE LINK 我的代码。

我给出了两个值 a 和 b 。 a 代表 x 轴 b 代表 y 轴。问题是当我给出 a 和 b 的值时。当 a 和 b 之间的差异较小时,则不会出现图形 IE。 a= -9 , b= -9 。否则它会起作用

$(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]
        }, ]
    });
});

最佳答案

这是一个有效的 fiddle

只需删除:

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

来自 yAxis:{ --- 一些选项 --- }

也尝试使用一个值 positive 和其他 negativeab

希望这对您有所帮助。

关于javascript - 使用 JavaScript 创建 Highchart 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25912328/

相关文章:

javascript - 如何将 div 元素移动到另一个 div 元素内?

javascript - typescript/javascript 中的递归函数

javascript - 将 jQuery.Deferred 对象传递给 deferred.resolve 时,jQuery.Deferred 是否存在错误?

javascript - 用类 'ul:first-child' 替换选择器 '.list_wrapper:first-child'

javascript - 对齐2表,搜索表

html - Div 在智能手机和小型浏览器上未垂直对齐

javascript - Node 更新特定包

javascript regex - 替换字符串停止词

jquery - 哪种 jQuery 方法可以更好地自动适应父 DIV 宽度的子项?

html - 使用 DT 和 DD 格式化表格布局