I need to get a highcharts image, and I found a code to resolve my problem, obtaining the name of the image via ajax, and then I paste before the url of the Highcharts API, and I can download the image in PHP, now, I want to do this process in PHP, since the name, until the download; I have this code to get the name of highcharts image:
var optionsStr = JSON.stringify({
"xAxis": {
"categories": [
"PRUEBA",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
]
},
"series": [
{
"data": [1, 3, 2, 4],
"type": "line"
},
{
"data": [5, 3, 4, 2],
"type": "line"
}
]
}),
exportUrl ='https://export.highcharts.com/';
dataString = encodeURI('async=true&type=image/jpeg&width=800&options=' + optionsStr);
$.ajax(
{
type: 'POST',
data: dataString,
url: exportUrl,
success: function(data)
{
console.log('get the file from relative url: ', data);
grafica=exportUrl+data;
},
error: function(err)
{
console.log('error', err.statusText)
}
});
I get the name of the graphic: charts/chart.9973ffbcf0d748d6aae04ef6ec01979c.jpeg I want to know how get the same in PHP, I have this code:
$DataEncoded = json_encode(
array(
'xAxis'=>
array(
'categories'=> ['Ene','Feb', 'Mar', 'Abr']
),
'series'=>
array(
array(
'data'=>[1,2,3,4],
'type'=>'line'
),
array(
'data'=>[5,6,7,8],
'type'=>'line'
)
)
)
);
$DataExtra = 'async=true&type=image/jpeg&width=800&options=';
$dataString = urlencode('async=true&type=image/jpeg&width=800&options='.$DataEncoded);
$url ='https://export.highcharts.com/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
$json=curl_exec($ch);
if(curl_errno($ch)){
echo "Entro al curl Error";
throw new Exception(curl_error($ch));
}
var_dump(json_decode($json));
curl_close($ch);
But I receive a fantastic: NULL. Someone made this before? I tried making this process via Angular 5, but, I must to program a cron job to delegate the process, so, I decided to use PHP. I tried with file_get_contents() but the webservice give me: "No data chart found".