我试图更改Highstock名称。 names = [' MSFT',' AAPL',' GOOG'];名字= [' ONE',' TWO',' THREE'];我想用任何名字更改名称。请帮助。
<script type="text/javascript">
var seriesOptions = [],
seriesCounter = 0,
names = ['ONE', 'TWO', 'THREE'];
/**
* Create the chart when all data is loaded
*/
function createChart() {
Highcharts.stockChart('container', {
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
formatter: function () {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: 'percent',
showInNavigator: true
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2,
split: true
},
series: seriesOptions
});
}
$.each(names, function (i, name) {
$.getJSON('https://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();
}
});
});
</script>
但是当我更改这些名称时,图表不会加载。任何类型的帮助Apreciated。如何更改这些名称请帮忙。感谢
原始代码。
<div id="container" style="height: 400px; min-width: 310px; margin-bottom:20px;"></div>
<script type="text/javascript">
var seriesOptions = [],
seriesCounter = 0,
names = ['MSFT', 'AAPL', 'GOOG'];
/**
* Create the chart when all data is loaded
*/
function createChart() {
Highcharts.stockChart('container', {
rangeSelector: {
selected: 4
},
yAxis: {
labels: {
formatter: function () {
return (this.value > 0 ? ' + ' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: 'percent',
showInNavigator: true
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
valueDecimals: 2,
split: true
},
series: seriesOptions
});
}
$.each(names, function (i, name) {
$.getJSON('https://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();
}
});
});
</script>
答案 0 :(得分:0)
图表中填充了以下行的值:
$('.OpenButton').click(function() {
$(this).addClass('CloseButton');
$(this).removeClass('OpenButton');
});
$('.CloseButton').click(function() {
alert('Close');
});
其中$.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=' + name.toLowerCase() + '-c.json&callback=?', function (data) {
取名称变量的值
name.tolowercase()
并从文件中提取内容:
https://www.highcharts.com/samples/data/jsonp.php?filename=msft-c.json&callback=?
https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?
https://www.highcharts.com/samples/data/jsonp.php?filename=goog-c.json&callback=?
所以当你替换 names = [&#39; ONE&#39;,&#39; TWO&#39;,&#39; THREE&#39;];
它在服务器上找不到相应的文件
https://www.highcharts.com/samples/data/jsonp.php?filename=one-c.json&callback=?
希望它有所帮助:)。
需要将文件放在服务器上,并附上要加载图表的相关数据。
答案 1 :(得分:0)
如果您希望获取文件“one”,“two”和“three”的JSON响应,则会出现错误,因此图表无法加载。
为了处理该异常,我建议你使用jQuery的Ajax方法.fail()
和.always()
this。
如果您看到我的示例,即使没有数据,图表也会加载。