javascript - 如何向 highstock 图表添加辅助轴?

标签 javascript jquery json highcharts

对于 javascript,我还是一知半解。我需要一些帮助,将类似于收入的辅助轴添加到 highstock 图表中,该图表还使用 $.getJSON (JSONP) 来获取 json 文件来填充数据。

查看 JSFiddle 示例 here 。这是要播放的示例数据集 with 。最后,一个 secondary axis 的例子在 Highcharts 中。

$(function () {
    var seriesOptions = [],
        seriesCounter = 0,
        names = ['MSFT', 'AAPL', 'GOOG'],
        // create the chart when all data is loaded
        createChart = function () {

            $('#container').highcharts('StockChart', {

                rangeSelector: {
                    selected: 4
                },

                yAxis: {
                    labels: {
                        formatter: function () {
                            return (this.value > 0 ? ' + ' : '') + this.value + '%';
                        }
                    },
                    plotLines: [{
                        value: 0,
                        width: 2,
                        color: 'silver'
                    }]
                },

                yAxis: {
                floor: 0
            },

                plotOptions: {
                    series: {
                        compare: 'value'
                    }
                },

                tooltip: {
                    pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
                    valueDecimals: 2
                },

                series: seriesOptions
            });
        };

    $.each(names, function (i, name) {

        $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=' + name.toLowerCase() + '-c.json&callback=?',    function (data) {

            seriesOptions[i] = {
                name: name,
                data: data
            };

            // As we're loading the data asynchronously, we don't know what order it will arrive. So
            // we keep a counter and create the chart when all the data is loaded.
            seriesCounter += 1;

            if (seriesCounter === names.length) {
                createChart();
            }
        });
    });
});

非常感谢任何帮助和解释(以便我可以学习)。我仍在尝试学习如何将 jsonp 和图表结合在一起,尤其是多个系列的数据和 json 文件。

最佳答案

这样写:

yAxis: [{
    labels: { ... },
    title: { ... },
    ...
},
{
    labels: { ... },
    title: { ... },
    ...
}]

http://jsfiddle.net/5eem7a2a/1/

关于javascript - 如何向 highstock 图表添加辅助轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26676113/

相关文章:

javascript - Angular + Ionic 模板中的条件路由

php - 如果他或她的密码不正确,如何重定向并通知用户?

javascript - 知道折线路径变量何时更改

javascript - 如何在 HTML 中实现 "select all"复选框?

javascript - 通过指令表达式继承方法

添加 css 类的 jQuery/JavaScript 问题

javascript - 使用 JavaScript 从文本创建数组

JavaScript JSON 转义安全

json - 单击保存按钮时如何更改存储的 JSON 数据? swift 3

c++ - 如何反序列化数组?