Highcharts Spline Chart with Asynchronously Loaded Data
The following example demonstrates a spline chart with asynchronously loaded data. Here we use the jQuery.getJSON() method to asynchronously load a csv file:
We learned the Highcharts configuration syntax in the previous chapters. Now let's look at a complete example:
Import the data.js File
To load data asynchronously, you need to include the following js files:
Configure
X Axis
Set the X axis at weekly intervals:
var xAxis = {
tickInterval: 7 * 24 * 3600 * 1000, // 一周
tickWidth: 0,
gridLineWidth: 1,
labels: {
align: 'left',
x: 3,
y: -3
}
};
Y Axis
Set the Y axis at weekly intervals:
Configure two Y axes:
var yAxis = [{ // 左边 Y 轴
title: {
text: null
},
labels: {
align: 'left',
x: 3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
},{ // 右边 Y 轴
linkedTo: 0,
gridLineWidth: 0,
opposite: true,
title: {
text: null
},
labels: {
align: 'right',
x: -3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}
];
plotOptions
plotOptions is used to set the data point-related properties of the chart.
var plotOptions = {
series: {
cursor: 'pointer',
point: {
events: {
click: function (e) {
hs.htmlExpand(null, {
pageOrigin: {
x: e.pageX || e.clientX,
y: e.pageY || e.clientY
},
headingText: this.series.name,
maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x)
+ ':
' + this.y + ' visits',
width: 200
});
}
}
},
marker: {
lineWidth: 1
}
}
}
Example
Filename: highcharts_line_ajax.html
Highcharts 教程 | Runoob Tutorial(runoob.com)
The output of the above example is:
Highcharts Spline Chart