我有以下設置:使用php導出Serverside上的Highcharts?
第一個PHP文件:從MySQL數據庫獲取數據,將其放入highchart,出口額爲「export.highcharts.com」爲PNG和帖子的圖片的URL到PHP文件2號通過阿賈克斯職位。
第二PHP文件:從PHP文件編號爲1的Ajax Post獲取「imagelink」,然後連接到twitter api以發佈包含該圖片的推文。
現在,只要我在瀏覽器中執行第一個PHP文件,這一切都很好。
我需要通過cronjob在「服務器端」運行這個自動化。現在它不再工作了,因爲它包含ajax和ajax文章,它不會在服務器端執行。
首先PHP文件的代碼:
<!-- Bootstrap core JavaScript -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<!-- Highcharts -->
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-3d.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<?php
$server = "localhost";
$username = "test";
$password = "test";
$db = "test";
$connect = @mysql_connect($server, $username, $password);
?>
<?php if ($connect && mysql_select_db($db, $connect)) : ?> <?php
// Select twitterdata table
$printMarketdata = mysql_query("SELECT * FROM marketdata ORDER BY volume24h DESC LIMIT 10") or die("MySQL Error! ".mysql_error());
// Marketdata found
if (mysql_num_rows($printMarketdata) > 0) {
?>
<script>
// Create the chart
var options = {
chart: {
type: 'bar'
},
title: {
text: 'TOP 10 Highest Trading Volume (24h)'
},
subtitle: {
text: 'Trading Volume (24h)'
},
xAxis: {
type: 'category'
},
yAxis: {
title: {
text: 'Volume'
}
},
legend: {
enabled: false
},
plotOptions: {
series: {
cursor: 'pointer',
borderWidth: 0,
dataLabels: {
enabled: true,
format: '${point.y:,.0f}'
},
point: {
events: {
click: function() {
location.href = 'https://example.com/' +
this.options.key;
}
}
}
}
},
tooltip: {
headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>${point.y:,.0f}</b><br/>'
},
series: [{
name: 'Trading Volume (24h)',
colorByPoint: true,
data: [
<?php // output data of each row
while ($marketdata = mysql_fetch_array($printMarketdata))
{
?>
{
name: '<?php echo $marketdata['name'];?>',
y: <?php echo $marketdata['volume24h'];?>,
key: '<?php echo $marketdata['symbol'];?>'
},
<?php
}
?>
]
}],
navigation: {
buttonOptions: {
enabled: false
}
},
credits: {
enabled: false
}
};
// URL to Highcharts export server
var exportUrl = 'https://export.highcharts.com/';
// POST parameter for Highcharts export server
var object = {
options: JSON.stringify(options),
type: 'image/png',
async: true
};
// Ajax request
$.ajax({
type: 'post',
url: exportUrl,
data: object,
success: function (data) {
//Submit data from your server
// Ajax request
$.ajax({
type: 'post',
url: 'posttweet.php',//this your local file
data: {'url' : exportUrl+data},
success: function (data2) {
//Response from your server
//if your teste.php print response. echo "" or die("") ;
alert(data2);
}
});
}
});
</script>
<?php
// No Data found
} else {
echo "0 results";
}
?>
<?php else : ?>
<h2>Database connection failed!</h2>
<?php endif; ?>
難道你們有什麼好的代碼,我可以使用(最好是PHP),這樣我就可以讓highchart和出口作爲服務器端的圖像?
要使用高圖服務器端,您將需要在您的服務器上一個完整的瀏覽器... PHP不會這樣做,它只會用來調用命令行和東西... – Salketer
是的,那麼該怎麼辦這是最好的方式? – user8607695