Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将次轴添加到highstock图表?_Javascript_Jquery_Json_Highcharts_Highstock - Fatal编程技术网

Javascript 如何将次轴添加到highstock图表?

Javascript 如何将次轴添加到highstock图表?,javascript,jquery,json,highcharts,highstock,Javascript,Jquery,Json,Highcharts,Highstock,说到javascript,我还是很不了解。我需要一些帮助,在highstock图表中添加一个类似于revenue的次轴,该图表还使用$.getJSON(JSONP)插入一个json文件来填充数据 查看JSFIDLE示例。下面是要播放的示例数据集。最后,举一个海图中的例子 $(function () { var seriesOptions = [], seriesCounter = 0, names = ['MSFT', 'AAPL', 'GOOG'],

说到javascript,我还是很不了解。我需要一些帮助,在highstock图表中添加一个类似于revenue的次轴,该图表还使用$.getJSON(JSONP)插入一个json文件来填充数据

查看JSFIDLE示例。下面是要播放的示例数据集。最后,举一个海图中的例子

$(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();
            }
        });
    });
});
$(函数(){
var系列选项=[],
序列计数器=0,
名称=['MSFT'、'AAPL'、'GOOG'],
//在加载所有数据时创建图表
createChart=函数(){
$(“#容器”).highcharts('StockChart'{
范围选择器:{
选定:4
},
亚克斯:{
标签:{
格式化程序:函数(){
返回(this.value>0?'+':'')+this.value+'%;
}
},
绘图线:[{
值:0,
宽度:2,
颜色:“银色”
}]
},
亚克斯:{
楼层:0
},
打印选项:{
系列:{
比较:“值”
}
},
工具提示:{
pointFormat:“{series.name}:{point.y}({point.change}%)
”, 数值小数:2 }, 系列:系列选项 }); }; $.each(名称、函数(i、名称){ $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=“+name.toLowerCase()+”-c.json&callback=?”,函数(数据){ 系列选项[i]={ 姓名:姓名,, 数据:数据 }; //当我们异步加载数据时,我们不知道数据的到达顺序 //我们保留一个计数器,并在加载所有数据时创建图表。 序列计数器+=1; if(serieCounter==names.length){ createChart(); } }); }); });
非常感谢您的任何帮助和解释(以便我能够学习)。我仍在努力学习如何将jsonp和图表联系在一起,特别是多系列数据和json文件。

这样写:

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

次Y轴?如果是这样,您只需要使用一个数组。例如:
yAxis:[{..axis1属性..},{..axis2属性..}]
。只需注意,只要轴上没有附加序列,它就不会显示标签。只需将属性“yAxis:n”添加到序列中,
n
是轴键(第一个是0,第二个是1…),因此,我需要添加一个新的轴标签和附加到该标签的序列。我以前确实尝试过添加新标签,但没有附加任何系列,所以没有显示任何内容。我想这就是原因。正如@MorKadosh所说,你需要一个axis对象数组,然后在系列对象中,参考particualr yAxis。谢谢你,Raein Hashemi。这正是我需要的。顺便说一下,我编辑了您的示例以显示x轴上的时间。