我有一个图表,其中包含从 xml 文件中提取的数据。而且由于某种原因我无法摆脱间距。如果需要,我会将我的代码放在一起并发布在http://jsfiddle.net
***************************解决方案:********************* ************
好的,很抱歉,我仍然无法在 JSFiddle 上使用它,但这是我对代码所做的。希望有一天这会帮助别人。
这是我的原始代码:
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'column',
},
title: {
text: 'Donations'
},
xAxis: {
categories: [],
startOnTick: false,
},
yAxis: {
title: {
text: 'Money $'
}
},
plotOptins: {
column: {
size:'150%'
}
},
legend: {
enabled: false,
},
series: []
};
// Load the data from the XML file
$.get('data.xml', function(xml) {
// Split the lines
var $xml = $(xml);
// push categories
$xml.find('stock symbol').each(function(i, category) {options.xAxis.categories.push($(category).text());
});
// push series
$xml.find('stock').each(function(i, series) {
var seriesOptions = {
name: $(series).find('symbol').text(),
data: []
};
// push data points
$(series).find('price').each(function(i, point) {
seriesOptions.data.push(
parseInt($(point).text())
);
});
// add it to the options
options.series.push(seriesOptions);
});
var chart = new Highcharts.Chart(options);
});
});
这是我的新代码:
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'column',
},
title: {
text: 'Donations'
},
xAxis: {
categories: [],
},
yAxis: {
title: {
text: 'Money $'
}
},
plotOptins: {
column: {
size:'150%'
}
},
legend: {
enabled: false,
},
series: []
};
// Load the data from the XML file
$.get('data.xml', function(xml) {
// Split the lines
var $xml = $(xml);
// push categories
$xml.find('stock symbol').each(function(i, category) {
options.xAxis.categories.push(i);
});
var seriesOptions = {
//name: $(series).find('symbol').text(),
data: []
};
// push series
$xml.find('stock').each(function(i, series) {
// push data points
$(series).find('price').each(function(i, point) {
seriesOptions.data.push(parseInt($(point).text())
);
});
// add it to the options
}); options.series.push(seriesOptions);
var chart = new Highcharts.Chart(options);
});
});