在图表(高图)中,其站点上的所有示例均通过链接从JSON对象提取数据。如何从同一页面上的数组中获取它?
我已经能够从同一js页上的数组中获取图表数据,但如果是股票图表,则无法执行相同操作。
这是官方网站上的highchart stock获取数据的方式:
$.each(names, function (i, name) {
// data from JSON
$.getJSON('https://www.highcharts.com/samples/data/' +
name.toLowerCase() + '-c.json', function (data) {
// .
// .
// .
// etc
这是一个股票图表的摆弄,我无法从同一页面上的数组中获取数据:https://jsfiddle.net/omaraziz/shjuLtkq/2/
如何从同一javascript页面中的数组加载数据,而不是从外部JSON获取数据?
答案 0 :(得分:1)
我已经能够从同一js上的数组中获取图表数据 页,但如果是股票图表,则无法执行此操作。
Highcharts和Highstock的工作原理相同,因此问题可能出在其他方面。
如何从同一javascript页面中的数组加载数据 从外部JSON获取它?
只需将series.data
(请参阅:https://api.highcharts.com/highstock/series.line.data)添加为具有数据的数组或对象。查看此演示:https://jsfiddle.net/BlackLabel/shjuLtkq/8/
代码:
var usdeur = [
[Date.UTC(2007, 0, 1), 0.7537],
[Date.UTC(2007, 0, 2), 0.7537],
[Date.UTC(2007, 0, 3), 0.7559],
[Date.UTC(2007, 0, 4), 0.7631],
[Date.UTC(2007, 0, 5), 0.7644],
[Date.UTC(2007, 0, 8), 0.769],
[Date.UTC(2007, 0, 9), 0.7683],
[Date.UTC(2007, 0, 10), 0.77],
[Date.UTC(2007, 0, 11), 0.7703],
[Date.UTC(2007, 0, 12), 0.7757],
[Date.UTC(2007, 0, 15), 0.7728],
[Date.UTC(2007, 0, 16), 0.7721],
[Date.UTC(2007, 0, 17), 0.7748],
[Date.UTC(2007, 0, 18), 0.774],
[Date.UTC(2007, 0, 19), 0.7718],
[Date.UTC(2007, 0, 22), 0.7731],
[Date.UTC(2007, 0, 23), 0.767],
[Date.UTC(2007, 0, 24), 0.769],
[Date.UTC(2007, 0, 25), 0.7706],
[Date.UTC(2007, 0, 26), 0.7752],
[Date.UTC(2007, 0, 29), 0.774],
[Date.UTC(2007, 0, 30), 0.771],
[Date.UTC(2007, 0, 31), 0.7721],
[Date.UTC(2007, 1, 1), 0.7681],
[Date.UTC(2007, 1, 2), 0.7681],
[Date.UTC(2007, 1, 5), 0.7738],
[Date.UTC(2007, 1, 6), 0.772],
[Date.UTC(2007, 1, 7), 0.7701],
[Date.UTC(2007, 1, 8), 0.7699],
[Date.UTC(2007, 1, 9), 0.7689],
[Date.UTC(2007, 1, 12), 0.7719],
[Date.UTC(2007, 1, 13), 0.768],
[Date.UTC(2007, 1, 14), 0.7645],
[Date.UTC(2007, 1, 15), 0.7613],
[Date.UTC(2007, 1, 16), 0.7624],
[Date.UTC(2007, 1, 19), 0.7616],
[Date.UTC(2007, 1, 20), 0.7608],
[Date.UTC(2007, 1, 21), 0.7608],
[Date.UTC(2007, 1, 22), 0.7631],
[Date.UTC(2007, 1, 23), 0.7615],
[Date.UTC(2007, 1, 26), 0.76],
[Date.UTC(2007, 1, 27), 0.756],
[Date.UTC(2007, 1, 28), 0.757],
[Date.UTC(2007, 2, 1), 0.7562],
[Date.UTC(2007, 2, 2), 0.7598],
[Date.UTC(2007, 2, 5), 0.7645],
[Date.UTC(2007, 2, 6), 0.7635],
[Date.UTC(2007, 2, 7), 0.7614],
[Date.UTC(2007, 2, 8), 0.7604],
[Date.UTC(2007, 2, 9), 0.7603],
[Date.UTC(2007, 2, 12), 0.7602],
[Date.UTC(2007, 2, 13), 0.7566],
[Date.UTC(2007, 2, 14), 0.7587],
[Date.UTC(2007, 2, 15), 0.7562],
[Date.UTC(2007, 2, 16), 0.7506],
[Date.UTC(2007, 2, 19), 0.7518],
[Date.UTC(2007, 2, 20), 0.7522],
[Date.UTC(2007, 2, 21), 0.7524],
[Date.UTC(2007, 2, 22), 0.7491],
[Date.UTC(2007, 2, 23), 0.7505],
[Date.UTC(2007, 2, 26), 0.754],
[Date.UTC(2007, 2, 27), 0.7493],
[Date.UTC(2007, 2, 28), 0.7493],
[Date.UTC(2007, 2, 29), 0.7491],
[Date.UTC(2007, 2, 30), 0.751],
[Date.UTC(2007, 3, 2), 0.7483],
[Date.UTC(2007, 3, 3), 0.7487],
[Date.UTC(2007, 3, 4), 0.7491],
[Date.UTC(2007, 3, 5), 0.7479],
[Date.UTC(2007, 3, 6), 0.7479],
[Date.UTC(2007, 3, 9), 0.7479],
[Date.UTC(2007, 3, 10), 0.7449],
[Date.UTC(2007, 3, 11), 0.7454],
[Date.UTC(2007, 3, 12), 0.7427],
[Date.UTC(2007, 3, 13), 0.7391],
[Date.UTC(2007, 3, 16), 0.7381],
[Date.UTC(2007, 3, 17), 0.7382],
[Date.UTC(2007, 3, 18), 0.7366],
[Date.UTC(2007, 3, 19), 0.7353],
[Date.UTC(2007, 3, 20), 0.7351],
[Date.UTC(2007, 3, 23), 0.7377],
[Date.UTC(2007, 3, 24), 0.7364],
[Date.UTC(2007, 3, 25), 0.7328],
[Date.UTC(2007, 3, 26), 0.7356],
[Date.UTC(2007, 3, 27), 0.7331],
[Date.UTC(2007, 3, 30), 0.7351],
[Date.UTC(2007, 4, 1), 0.7351],
[Date.UTC(2007, 4, 2), 0.736],
[Date.UTC(2007, 4, 3), 0.7347],
[Date.UTC(2007, 4, 4), 0.7375],
[Date.UTC(2007, 4, 7), 0.7346],
[Date.UTC(2007, 4, 8), 0.7377],
[Date.UTC(2007, 4, 9), 0.7389],
[Date.UTC(2007, 4, 10), 0.7394],
[Date.UTC(2007, 4, 11), 0.7416],
[Date.UTC(2007, 4, 14), 0.7382],
[Date.UTC(2007, 4, 15), 0.7388],
[Date.UTC(2007, 4, 16), 0.7368],
[Date.UTC(2007, 4, 17), 0.74],
[Date.UTC(2007, 4, 18), 0.7421],
[Date.UTC(2007, 4, 21), 0.7439],
[Date.UTC(2007, 4, 22), 0.7434],
[Date.UTC(2007, 4, 23), 0.7414],
[Date.UTC(2007, 4, 24), 0.7437],
[Date.UTC(2007, 4, 25), 0.7441],
[Date.UTC(2007, 4, 28), 0.7434],
[Date.UTC(2007, 4, 29), 0.7403],
[Date.UTC(2007, 4, 30), 0.7453],
[Date.UTC(2007, 4, 31), 0.7434],
[Date.UTC(2007, 5, 1), 0.7444],
[Date.UTC(2007, 5, 4), 0.7418],
[Date.UTC(2007, 5, 5), 0.7391],
[Date.UTC(2007, 5, 6), 0.7401],
[Date.UTC(2007, 5, 7), 0.7425],
[Date.UTC(2007, 5, 8), 0.7492],
[Date.UTC(2007, 5, 11), 0.7489],
[Date.UTC(2007, 5, 12), 0.7494],
[Date.UTC(2007, 5, 13), 0.7527],
[Date.UTC(2007, 5, 14), 0.7518],
[Date.UTC(2007, 5, 15), 0.7512],
[Date.UTC(2007, 5, 18), 0.7461],
[Date.UTC(2007, 5, 19), 0.7462],
[Date.UTC(2007, 5, 20), 0.7449],
[Date.UTC(2007, 5, 21), 0.7465],
[Date.UTC(2007, 5, 22), 0.7441],
[Date.UTC(2007, 5, 25), 0.743],
[Date.UTC(2007, 5, 26), 0.743],
[Date.UTC(2007, 5, 27), 0.7443],
[Date.UTC(2007, 5, 28), 0.7427],
[Date.UTC(2007, 5, 29), 0.7406],
[Date.UTC(2007, 6, 2), 0.736],
[Date.UTC(2007, 6, 3), 0.7353],
[Date.UTC(2007, 6, 4), 0.7344],
[Date.UTC(2007, 6, 5), 0.7332],
[Date.UTC(2007, 6, 6), 0.7356],
[Date.UTC(2007, 6, 9), 0.7343],
[Date.UTC(2007, 6, 10), 0.7318],
[Date.UTC(2007, 6, 11), 0.7272],
[Date.UTC(2007, 6, 12), 0.7254],
[Date.UTC(2007, 6, 13), 0.7257],
[Date.UTC(2007, 6, 16), 0.7257],
[Date.UTC(2007, 6, 17), 0.7263],
[Date.UTC(2007, 6, 18), 0.7258],
[Date.UTC(2007, 6, 19), 0.7237],
[Date.UTC(2007, 6, 20), 0.7246],
[Date.UTC(2007, 6, 23), 0.7236],
[Date.UTC(2007, 6, 24), 0.723],
[Date.UTC(2007, 6, 25), 0.7277],
[Date.UTC(2007, 6, 26), 0.7289],
[Date.UTC(2007, 6, 27), 0.7326],
[Date.UTC(2007, 6, 30), 0.7322],
[Date.UTC(2007, 6, 31), 0.7297],
[Date.UTC(2007, 7, 1), 0.732],
[Date.UTC(2007, 7, 2), 0.732],
[Date.UTC(2007, 7, 3), 0.7303],
[Date.UTC(2007, 7, 6), 0.7238],
[Date.UTC(2007, 7, 7), 0.7251],
[Date.UTC(2007, 7, 8), 0.7251],
[Date.UTC(2007, 7, 9), 0.7285],
[Date.UTC(2007, 7, 10), 0.7327],
[Date.UTC(2007, 7, 13), 0.7326],
[Date.UTC(2007, 7, 14), 0.7359],
[Date.UTC(2007, 7, 15), 0.7422],
[Date.UTC(2007, 7, 16), 0.7461],
[Date.UTC(2007, 7, 17), 0.7434],
[Date.UTC(2007, 7, 20), 0.7422],
[Date.UTC(2007, 7, 21), 0.7404],
[Date.UTC(2007, 7, 22), 0.7412],
[Date.UTC(2007, 7, 23), 0.7368],
[Date.UTC(2007, 7, 24), 0.7346],
[Date.UTC(2007, 7, 27), 0.7323],
[Date.UTC(2007, 7, 28), 0.732],
[Date.UTC(2007, 7, 29), 0.7337],
[Date.UTC(2007, 7, 30), 0.7349],
[Date.UTC(2007, 7, 31), 0.7298],
[Date.UTC(2007, 8, 3), 0.7337],
[Date.UTC(2007, 8, 4), 0.7365],
[Date.UTC(2007, 8, 5), 0.736],
[Date.UTC(2007, 8, 6), 0.7317],
[Date.UTC(2007, 8, 7), 0.7302],
[Date.UTC(2007, 8, 10), 0.725],
[Date.UTC(2007, 8, 11), 0.7235],
[Date.UTC(2007, 8, 12), 0.7203],
[Date.UTC(2007, 8, 13), 0.7197],
[Date.UTC(2007, 8, 14), 0.7216],
[Date.UTC(2007, 8, 17), 0.7207],
[Date.UTC(2007, 8, 18), 0.7212],
[Date.UTC(2007, 8, 19), 0.7157],
[Date.UTC(2007, 8, 20), 0.7129],
[Date.UTC(2007, 8, 21), 0.7119],
[Date.UTC(2007, 8, 24), 0.7087],
[Date.UTC(2007, 8, 25), 0.709],
[Date.UTC(2007, 8, 26), 0.708],
[Date.UTC(2007, 8, 27), 0.7053],
[Date.UTC(2007, 8, 28), 0.7054],
[Date.UTC(2007, 9, 1), 0.7027],
[Date.UTC(2007, 9, 2), 0.7061],
[Date.UTC(2007, 9, 3), 0.7046],
[Date.UTC(2007, 9, 4), 0.7089],
[Date.UTC(2007, 9, 5), 0.7075],
[Date.UTC(2007, 9, 8), 0.7099],
[Date.UTC(2007, 9, 9), 0.7125],
[Date.UTC(2007, 9, 10), 0.707],
[Date.UTC(2007, 9, 11), 0.7044],
[Date.UTC(2007, 9, 12), 0.7057],
[Date.UTC(2007, 9, 15), 0.703],
[Date.UTC(2007, 9, 16), 0.7068],
[Date.UTC(2007, 9, 17), 0.7043],
[Date.UTC(2007, 9, 18), 0.6994],
[Date.UTC(2007, 9, 19), 0.7],
[Date.UTC(2007, 9, 22), 0.706],
[Date.UTC(2007, 9, 23), 0.7017],
[Date.UTC(2007, 9, 24), 0.7028],
[Date.UTC(2007, 9, 25), 0.699],
[Date.UTC(2007, 9, 26), 0.6953],
[Date.UTC(2007, 9, 29), 0.695],
[Date.UTC(2007, 9, 30), 0.6942],
[Date.UTC(2007, 9, 31), 0.6923],
[Date.UTC(2007, 10, 1), 0.6934],
[Date.UTC(2007, 10, 2), 0.6908],
[Date.UTC(2007, 10, 5), 0.6903],
[Date.UTC(2007, 10, 6), 0.6875],
[Date.UTC(2007, 10, 7), 0.6794],
[Date.UTC(2007, 10, 8), 0.6819],
[Date.UTC(2007, 10, 9), 0.6812],
[Date.UTC(2007, 10, 12), 0.686],
[Date.UTC(2007, 10, 13), 0.6847],
[Date.UTC(2007, 10, 14), 0.6804],
[Date.UTC(2007, 10, 15), 0.6832],
[Date.UTC(2007, 10, 16), 0.6826],
[Date.UTC(2007, 10, 19), 0.6825],
[Date.UTC(2007, 10, 20), 0.6765],
[Date.UTC(2007, 10, 21), 0.6751],
[Date.UTC(2007, 10, 22), 0.6745],
[Date.UTC(2007, 10, 23), 0.6754],
[Date.UTC(2007, 10, 26), 0.6737],
[Date.UTC(2007, 10, 27), 0.6724],
[Date.UTC(2007, 10, 28), 0.6782],
[Date.UTC(2007, 10, 29), 0.6786],
[Date.UTC(2007, 10, 30), 0.6776],
[Date.UTC(2007, 11, 3), 0.6819],
[Date.UTC(2007, 11, 4), 0.6785],
[Date.UTC(2007, 11, 5), 0.6794],
[Date.UTC(2007, 11, 6), 0.6872],
[Date.UTC(2007, 11, 7), 0.6827],
[Date.UTC(2007, 11, 10), 0.6795],
[Date.UTC(2007, 11, 11), 0.6817],
[Date.UTC(2007, 11, 12), 0.6815],
[Date.UTC(2007, 11, 13), 0.6812],
[Date.UTC(2007, 11, 14), 0.6893],
[Date.UTC(2007, 11, 17), 0.6949],
[Date.UTC(2007, 11, 18), 0.6938],
[Date.UTC(2007, 11, 19), 0.6953],
[Date.UTC(2007, 11, 20), 0.697],
[Date.UTC(2007, 11, 21), 0.6955],
[Date.UTC(2007, 11, 24), 0.6946],
[Date.UTC(2007, 11, 25), 0.6946],
[Date.UTC(2007, 11, 26), 0.6946],
[Date.UTC(2007, 11, 27), 0.689],
[Date.UTC(2007, 11, 28), 0.6807],
[Date.UTC(2007, 11, 31), 0.6794]
];
Highcharts.stockChart('container', {
title: {
text: 'xAxis: {min: Date.UTC(2010, 8, 1), max: Date.UTC(2014, 8, 1)}'
},
series: [{
name: 'USD to EUR',
data: usdeur
}, {
name: "UK WE",
data: usdeur
}]
});