I have the following code
<?php
if(isset($_GET['mod']))
{
require_once 'PSController.php';
$fecha_actual = date("d-m-Y");
$fecha = date("d-m-Y",strtotime($fecha_actual."- 1 days"));
$ps = new PSController();
$PDP_ContextImprimir = $ps->PDP_ContextImprimir();
}
?>
<h2 class="text-center">Reportes <?php echo $fecha; ?></h2>
<!-- GRAFICOS !-->
<div class="col-md-5">
<div id="grafico1">
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script type="text/javascript">
chartCPU = new Highcharts.chart('grafico1',
{
chart: {
type: 'line'
},
title: {
text: 'PDP Context 3G'
},
xAxis: {
gridLineWidth: 1,
categories:
[
<?php
foreach($PDP_ContextImprimir['LABEL'] as $hora)
{
echo "'$hora',";
}
?>
]
},
yAxis:
[
{
min: 0,
title:
{
text: '',
}
},
{
min: 0,
max: 100,
title:
{
text: '',
},
opposite: true
}
],
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
credits: {
enabled: false
},
tooltip: {
split: true
},
series:
[
{
name: 'RATE',
yAxis: 1,
data:
[
<?php
for ($j=0; $j < count($PDP_ContextImprimir['SUCC_RATE']) ; $j++)
{
echo $PDP_ContextImprimir['SUCC_RATE'][$j].',';
}
?>
],
cursor: 'pointer'
},{
name: 'REQUEST',
yAxis: 0,
data:
[
<?php
for ($k=0; $k < count($PDP_ContextImprimir['REQUEST']) ; $k++)
{
echo $PDP_ContextImprimir['REQUEST'][$k].',';
}
?>
],
cursor: 'pointer'
},{
name: 'SUCCESS',
yAxis: 0,
data:
[
<?php
for ($p=0; $p < count($PDP_ContextImprimir['SUCCESS']) ; $p++)
{
echo $PDP_ContextImprimir['SUCCESS'][$p].',';
}
?>
],
cursor: 'pointer'
}
]
});
</script>
</div>
</div>
<!-- END GRAFICOS !-->
What I want to do is print that page with body onload="window.print();" I get it to print but it doesn't show me the lines of the graph and if I remove the onload="window.print();" the graph is fine with its perfect lines
It doesn't work for you in the event
onload
ofbody
because you need to load the data of your chart to be able to print later, therefore you can listen to the eventonload
ofchart
and there trigger the print action.Try changing the start of your Chart declaration:
If you want to print the graph specifically, you should check that you have included this script:
And I would change the lines of code above to the following:
You can check it works in this Fiddle