we are two students that have to load on a highcharts chart some x and y data taken from a .php file that contains the data in JSON format, but after making the AJAX call we do not know how to recall the data on the chart, we have seen a lot of guides but, we can’t find anything, if you can help us we will be glad.
Our complete code:
Html:
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<title>Grafico Stage</title>
</head>
<body>
<div id="container"></div>
<script src="index.js"></script>
</body>
</html>
.javaScript
Highcharts.chart('container', {
colors: ["#669900"],
chart: {
type: 'spline',
zoomType: 'x,y',
},
title: {
text: 'Grafico Stage Samela-Ungureanu'
},
credits: {
text: 'Powered by Sirius s.r.l',
href: 'http://www.sirius.to.it/',
position: {
align: 'left',
x: 70,
y: -355
},
style: {
fontSize: "15px",
color: "#669900"
}
},
yAxis: {
title: {
text: null,
},
},
series: [
{
name: 'Potenza',
data: []
},
],
xAxis: {
categories: []
},
series: [
{
name: 'SSEMontalto.Montalto.WPP.Line 01.WTG01.DMAV.Active Power',
data: []
},
]
});
$.ajax({
url: "getData.php",
cache: false,
dataType: "json",
type: "GET",
complete: function (data) {
console.log("Ajax request finished");
},
success: function (data) {
console.log(data)
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("Error:" + textStatus);
}
})
});
.php with JSON format
{"SSEMontalto.Montalto.WPP.Line 01.WTG01.DMAV.Active Power":[{"unixdate":1641769200000,"value":558.571,"valid":true},{"unixdate":1641769800000,"value":613.30537229,"valid":true},{"unixdate":1641770400000,"value":622.3602128064896,"valid":true},{"unixdate":1641771000000,"value":659.07448648037,"valid":true},{"unixdate":1641771600000,"value":779.1308358631477,"valid":true},{"unixdate":1641772200000,"value":929.2911635973804,"valid":true},{"unixdate":1641772800000,"value":986.1693585565218,"valid":true},{"unixdate":1641773400000,"value":941.6240886305237,"valid":true},{"unixdate":1641774000000,"value":954.4424173490511,"valid":true},{"unixdate":1641774600000,"value":871.015560090988,"valid":true},{"unixdate":1641775200000,"value":857.4163941512874,"valid":true},{"unixdate":1641775800000,"value":869.1389910921237,"valid":true},{"unixdate":1641776400000,"value":788.9252844652405,"valid":true},{"unixdate":1641777000000,"value":882.9557112700836,"valid":true},{"unixdate":1641777600000,"value":975.8267588928936,"valid":true},{"unixdate":1641778200000,"value":1082.4865752934047,"valid":true},{"unixdate":1641778800000,"value":1028.8623553265202,"valid":false},{"unixdate":1641779400000,"value":1004.2612275483077,"valid":false},{"unixdate":1641780000000,"value":916.8332578616346,"valid":false},{"unixdate":1641780600000,"value":834.2073278298863,"valid":false},{"unixdate":1641781200000,"value":802.6701198012775,"valid":false},{"unixdate":1641781800000,"value":832.7614199225076,"valid":true},{"unixdate":1641782400000,"value":777.5618292029441,"valid":true},{"unixdate":1641783000000,"value":916.6365379741827,"valid":true},{"unixdate":1641783600000,"value":981.8332283741345,"valid":true},{"unixdate":1641784200000,"value":942.9703055286295,"valid":true},{"unixdate":1641784800000,"value":886.8984622509806,"valid":true},{"unixdate":1641785400000,"value":1017.234399567998,"valid":true},{"unixdate":1641786000000,"value":1175.1203679593466,"valid":true},{"unixdate":1641786600000,"value":1371.0740395573036,"valid":true},{"unixdate":1641787200000,"value":1501.2547774651905,"valid":true},{"unixdate":1641787800000,"value":1356.8190553252646,"valid":true},{"unixdate":1641788400000,"value":1367.9571829504296,"valid":true},{"unixdate":1641789000000,"value":1477.3964935008298,"valid":true},{"unixdate":1641789600000,"value":1590.378912944812,"valid":true},{"unixdate":1641790200000,"value":1647.0536558865135,"valid":true},{"unixdate":1641790800000,"value":1889.096425887316,"valid":true},{"unixdate":1641791400000,"value":1847.0262484828054,"valid":true},{"unixdate":1641792000000,"value":1960.263733724789,"valid":true},{"unixdate":1641792600000,"value":2210.8442468068292,"valid":true},{"unixdate":1641793200000,"value":2519.3321879407736,"valid":true},{"unixdate":1641793800000,"value":2276.6172056223713,"valid":true},{"unixdate":1641794400000,"value":2315.142121975913,"valid":true},{"unixdate":1641795000000,"value":2382.065935295871,"valid":true},{"unixdate":1641795600000,"value":2344.3363929467196,"valid":true},{"unixdate":1641796200000,"value":2522.0488132140454,"valid":true},{"unixdate":1641796800000,"value":2652.630412567016,"valid":true},{"unixdate":1641797400000,"value":3045.331124104262,"valid":true},{"unixdate":1641798000000,"value":2870.0692725809376,"valid":true},{"unixdate":1641798600000,"value":2806.2389319587373,"valid":true},{"unixdate":1641799200000,"value":2678.3053052896703,"valid":true},{"unixdate":1641799800000,"value":2514.4331951855215,"valid":true},{"unixdate":1641800400000,"value":2664.9572239821073,"valid":true},{"unixdate":1641801000000,"value":3092.4003729654933,"valid":true},{"unixdate":1641801600000,"value":3103.059877051105,"valid":true},{"unixdate":1641802200000,"value":3015.2091488719116,"valid":true},{"unixdate":1641802800000,"value":2996.9430118480454,"valid":true},{"unixdate":1641803400000,"value":3459.90777137532,"valid":true},{"unixdate":1641804000000,"value":3149.616322622838,"valid":true},{"unixdate":1641804600000,"value":2876.0973419336256,"valid":true},{"unixdate":1641805200000,"value":2712.3496158679764,"valid":true},{"unixdate":1641805800000,"value":3128.5542397236854,"valid":true},{"unixdate":1641806400000,"value":3654.620635133223,"valid":true},{"unixdate":1641807000000,"value":3857.583646725982,"valid":true},{"unixdate":1641807600000,"value":3889.5321544881663,"valid":true},{"unixdate":1641808200000,"value":4231.877106129751,"valid":true},{"unixdate":1641808800000,"value":4260.962797480181,"valid":true},{"unixdate":1641809400000,"value":4643.022026716241,"valid":true},{"unixdate":1641810000000,"value":5323.015817638969,"valid":true},{"unixdate":1641810600000,"value":6113.084440372033,"valid":true},{"unixdate":1641811200000,"value":7118.216123311324,"valid":true},{"unixdate":1641811800000,"value":8109.207053782603,"valid":true},{"unixdate":1641812400000,"value":8321.01143282035,"valid":true},{"unixdate":1641813000000,"value":8448.655748199813,"valid":true},{"unixdate":1641813600000,"value":7753.37362340171,"valid":true},{"unixdate":1641814200000,"value":9149.438324657798,"valid":true},{"unixdate":1641814800000,"value":9207.509809704403,"valid":true},{"unixdate":1641815400000,"value":8299.115306898586,"valid":true},{"unixdate":1641816000000,"value":7600.04762813729,"valid":true},{"unixdate":1641816600000,"value":7496.732580680392,"valid":true},{"unixdate":1641817200000,"value":7229.024260224295,"valid":true},{"unixdate":1641817800000,"value":6512.302649944357,"valid":true},{"unixdate":1641818400000,"value":6925.951089663522,"valid":true},{"unixdate":1641819000000,"value":7955.3967558267495,"valid":true},{"unixdate":1641819600000,"value":9233.765371314063,"valid":true},{"unixdate":1641820200000,"value":8361.017569713571,"valid":true},{"unixdate":1641820800000,"value":9688.253859747472,"valid":true},{"unixdate":1641821400000,"value":11162.38950228507,"valid":true},{"unixdate":1641822000000,"value":10203.975577229372,"valid":true},{"unixdate":1641822600000,"value":11722.123063609557,"valid":true},{"unixdate":1641823200000,"value":12441.474589654084,"valid":true},{"unixdate":1641823800000,"value":12923.071629545006,"valid":true},{"unixdate":1641824400000,"value":11823.447464587021,"valid":true},{"unixdate":1641825000000,"value":12596.795516350729,"valid":true},{"unixdate":1641825600000,"value":12336.230801095015,"valid":true},{"unixdate":1641826200000,"value":12052.374130361819,"valid":true},{"unixdate":1641826800000,"value":11394.278345721674,"valid":true},{"unixdate":1641827400000,"value":12538.12716029198,"valid":true},{"unixdate":1641828000000,"value":11657.210884137026,"valid":true},{"unixdate":1641828600000,"value":10614.496684972737,"valid":true}]}