我刚开始使用 Highcharts 并试图从我拥有的 API 数据中加载类别,但我似乎无法调用我在请求之前设置的选项对象
var categories = [];
$.ajax({
url: url,
data: '',
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function (result) {
$.each(result, function () {
$.each(this.Values, function (i) {
var date = this.Date.substr(0, 4);
//console.log(date);
//console.log(this.Value);
categories[i] = this.Value
//console.log(categories);
//options.xAxis.categories.push(this.Value);
});
});
console.log(options.xAxis.categories);
}
});
这是对象
var url = sApiURL + '/api/';
$(document).ready(function () {
//testing for Housing_Prices
var chart;
var options = {
chart: {
renderTo: 'Housing_Prices',
type: 'column'
},
title: {
text: 'Mean/Median prices for homes over the years'
},
xAxis: {
categories: []
},
yAxis: {
min: 0,
title: {
text: 'Price'
}
},
legend: {
layout: 'vertical',
backgroundColor: '#FFFFFF',
align: 'left',
verticalAlign: 'top',
x: 80,
y: 70,
floating: true,
shadow: true
},
tooltip: {
formatter: function () {
return "$600,000 in " + this.key;
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Existing Home Median Price',
data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
name: 'Existing Condo Median Price',
data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3]
}, {
name: 'Existing Single Family Median Price',
data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]
}, {
name: 'Starter Home Median Price',
data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1]
},
{
name: 'Existing Home Mean Price',
data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]
},
{
name: 'Existing Condo Mean Price',
data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 400.3, 51.2]
},
{
name: 'Existing Single Family Mean Price',
data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 200.2]
}]
};