I have a php website and I need add a google chart - so it is my first step with js.
(我有一个PHP网站,我需要添加一个Google图表-这是我使用JS的第一步。)
I have the below problem: (我有以下问题:)
I need to change the original function drawVisualization() for php code.
(我需要为PHP代码更改原始函数drawVisualization() 。)
- I created $cosafter with the same input (php),
(我用相同的输入(php)创建了$ cosafter ,)
- Made var coss with php echo (js)
(用php echo(js)制作var coss)
- Put the new coss id into function (js)
(将新的coss id放入函数(js))
Could you plese check and advise where I made a mistake?
(您能检查一下并告知我在哪里出错吗?)
Original code:
(原始代码:)
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawVisualization);
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['data', 'zysk/strata', 'Average'],
['2019-09-05',9.32,9.32],
['2019-09-06',10.88,10.1],
['2019-11-29',-7.86,4.1133333333333],
['2019-11-29',-43.61,-7.8175],
['2019-11-29',44,2.546],
['2019-11-29',4.71,2.9066666666667],
]);
var options = {
title : 'Trend ostatnich 10 transakcji',
vAxis: {title: 'Zysk/Strata'},
hAxis: {title: 'Data'},
seriesType: 'bars',
series: {1: {type: 'line', color: 'black'}} };
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
My code after changes:
(更改后的代码:)
<?php
require("zamkniete.php");
$cos='';
if ($lp22 >= 10){$ost10=$lp22-9;}else{$ost10=0;} //show only last 10 prices
for ($x=$ost10; $x <= $lp22; $x++){
if($x==0){$to=$zyskpop[$x];}else{$to=($zyskpop[$x]/($x+1));}
$cosbefore.= "['".$datatab[$x]."',".$zysktab[$x].",".$to."],</br>";
};
$cosafter = "[['data', 'zysk/strata', 'Average'],</br>".$cosbefore."]";
//echo $cosafter;
/*
FYI how $cosafter looks like:
[['data', 'zysk/strata', 'Average'],
['2019-09-05',9.32,9.32],
['2019-09-06',10.88,10.1],
['2019-11-29',-7.86,4.1133333333333],
['2019-11-29',-43.61,-7.8175],
['2019-11-29',44,2.546],
['2019-11-29',4.71,2.9066666666667],
]
*/
?>
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawVisualization);
var coss = "<?php echo $cosafter; ?>";
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable(coss);
var options = {
title : 'Trend ostatnich 10 transakcji',
vAxis: {title: 'Zysk/Strata'},
hAxis: {title: 'Data'},
seriesType: 'bars',
series: {1: {type: 'line', color: 'black'}} };
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
ask by Touchstone translate from so