我有以下设置:
First PHP:从mysql数据库获取数据,将其放入高位,以png的形式导出到"export.highcharts.com“,并通过ajax将图像的URL发布到PHP 2。
第二个PHP:从PHP 1获得Ajax的"imagelink“,然后连接到twitter,将包含图像的tweet发布到图表中。
现在,只要我在浏览器中执行第一个PHP文件,这一切都很好。
我需要通过cronjob在“服务器端”上自动运行这个程序。现在它不再工作了,因为它包含ajax和ajax post,它不会在服务器端执行。
第一个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),这样我就可以在服务器端制作高图表并作为图像导出?
发布于 2017-09-14 08:43:48
无法从PHP运行AJAX,因此需要用一些PHP替换javascript代码。
您可以使用cURL,或者像Guzzle这样的cURL库向另一个页面发送请求,以及API等等。
查看有关cURL:http://php.net/manual/en/curl.examples-basic.php的信息的PHP
粗略地说,像这样:
第一个PHP :从mysql数据库获取数据,将其放入高图表,以png 的形式导出到"export.highcharts.com“,并需要file2并传递结果
第二个PHP :从另一个PHP 1获取"imagelink“,然后连接到twitter,将包含图像的tweet发布到图表中。
https://stackoverflow.com/questions/46213722
复制相似问题