任何人都可以在这里分享来自外部json文件的数据的基本高图代码吗?
我尝试阅读与我的帖子相关的所有材料,但我仍然无法使用 getJSON 创建高级图表,希望有人可以在这里与我分享您的想法,谢谢。
这是我的json文件的一部分:
[
{
"indicator": "ClassC",
"month": 201611,
"ww": 201648,
"test_time": 0.0,
"p": 48.0,
"Product": "RB"
},
{
"indicator": "ClassC",
"month": 201612,
"ww": 201649,
"test_time": 47.48,
"p": 48.0,
"Product": "RB"
},
...
]
答案 0 :(得分:0)
请检查这个小提琴。你可能会发现答案就在这里
并检查那里使用的api。你可以找到返回的json格式
https://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?.
更新代码
$.getJSON('your url', function (data) {
var datas = JSON.parse(data)
var myArray = [];
for(var i in datas ) {
myArray.push(datas[i]);
}
var mydata = myArray.map(i=>([i.month,i.p]));
// Create the chart
Highcharts.stockChart('container', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
},
series: [{
name: 'AAPL',
data: mydata,
tooltip: {
valueDecimals: 2
}
}]
});
});
var datas部分应该替换为$ .getJson
中的数据答案 1 :(得分:0)
这是来自外部数据的高位图表(气泡图和仪表图)的完整代码
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<style>
.highcharts-point-select{
stroke: orange;
}
</style>
</head>
<body>
<div class="container">
<div class="col-md-6" id="container1"></div>
<div class="col-md-6" id="container2"></div>
</div>
<script>
$.getJSON(
'http://localhost/highcharts/bubble-chart/bubblechart.json',
function (data) {
Highcharts.chart('container1', {
chart: {
type: 'bubble',
plotBorderWidth: 1,
zoomType: 'xy'
},
xAxis: {
gridLineWidth: 1
},
plotOptions: {
series: {
allowPointSelect: true,
marker: {
states: {
select: {
fillColor : 'orange'
}
}
}
}
},
yAxis: {
startOnTick: false,
endOnTick: false
},
series: [{
data: data,
color: 'green',
} ]
});
Highcharts.chart('container2', {
chart: {
type: 'gauge',
plotBackgroundColor: null,
plotBackgroundImage: null,
plotBorderWidth: 0,
plotShadow: false
},
title: {
text: 'Speedometer'
},
pane: {
startAngle: -150,
endAngle: 150,
background: [{
backgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#FFF'],
[1, '#333']
]
},
borderWidth: 0,
outerRadius: '109%'
}, {
backgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#333'],
[1, '#FFF']
]
},
borderWidth: 1,
outerRadius: '107%'
}, {
// default background
}, {
backgroundColor: '#DDD',
borderWidth: 0,
outerRadius: '105%',
innerRadius: '103%'
}]
},
// the value axis
yAxis: {
min: 0,
max: 200,
minorTickInterval: 'auto',
minorTickWidth: 1,
minorTickLength: 10,
minorTickPosition: 'inside',
minorTickColor: '#666',
tickPixelInterval: 30,
tickWidth: 2,
tickPosition: 'inside',
tickLength: 10,
tickColor: '#666',
labels: {
step: 2,
rotation: 'auto'
},
title: {
text: 'km/h'
},
plotBands: [{
from: 0,
to: 120,
color: '#55BF3B' // green
}, {
from: 120,
to: 160,
color: '#DDDF0D' // yellow
}, {
from: 160,
to: 200,
color: '#DF5353' // red
}]
},
series: [{
name: 'Speed',
data: data[7],
tooltip: {
valueSuffix: ' km/h'
}
}]
},
// Add some life
function (chart) {
if (!chart.renderer.forExport) {
setInterval(function () {
var point = chart.series[0].points[0],
newVal,
inc = Math.round((Math.random() - 0.5) * 20);
newVal = point.y + inc;
if (newVal < 0 || newVal > 200) {
newVal = point.y - inc;
}
point.update(newVal);
}, 3000);
}
});
});
</script>
</body>
</html>
[
[9, 81, 103],
[98, 5, 89],
[51, 50, 73],
[41, 22, 14],
[58, 24, 20],
[78, 37, 34],
[55, 56, 53],
[91]
]