我在JavaScript中有一个月份值数组。
var myarray = new Array();
myarray2.push("January");
myarray2.push("February");
myarray2.push("March");
myarray2.push("April");
myarray2.push("May");
myarray2.push("Jun");
myarray2.push("Jul");
myarray2.push("Aug");
myarray2.push("Sept");
myarray2.push("Oct");
如何循环遍历此数组并添加到我的addAxis方法中?
目前我已静态添加它,如图所示,但我怎样才能动态添加它们?
chart1.addAxis("x", {
fixLower: "none",
fixUpper: "none",
natural: true,
majorTick: { length: 3 },
labels: [
{value: 1, text: "January"},
{value: 2, text: "February"},
{value: 3, text: "March"},
{value: 4, text: "April"},
{value: 5, text: "May"},
{value: 6, text: "Jun"},
{value: 7, text: "Jul"},
{value: 8, text: "Aug"},
{value: 9, text: "Sept"},
{value: 10, text: "Oct"}
]
});
答案 0 :(得分:4)
var i, l, labels = [];
for (i = 0, l = months.length; i < l; ++i) {
labels.push({value : i + 1, text : months[i]});
}
现在labels
变量应该具有您想要的格式的数据。