This question has been asked a couple of times on here already but unfortunately the answers don't fix my problem.
The website is currently viewable live at http://www.crosstrendanalysis.co.uk/jqplot_test.php
The relevant code is below, however the crux of the problem lies within the code below;
var line1 = "<?php echo $outputString; ?>";
When I use the output (via copy and paste) of the $outputString instead of using php it creates a graph perfectly fine, however when I try and use php it doesn't work.
I'm trying to use JQPlot with an array obtained from a MySql database. The array is created with the following code
$weeknumbers = array();
$completedquestionnaires = array();
$output = array();
while($row=mysqli_fetch_assoc($resultQuestionnaireCount)){
// $completedquestionnaires[] = $row['VolumeOfAnswers'];
// $weeknumbers[] = $row['WeekNumber'];
$temp1 = array();
$temp2 = array();
$temp1[] = "".$row['WeekNumber']."";
$temp2[] = "".$row['VolumeOfAnswers']."";
$output[] = '[' . json_encode(implode(", ", $temp1)) . ', ' . implode(", ", $temp2) . ']';
//$output[] = $temp1;
}
//$outputTemp = implode(',\n',$output);
$outputString = '['.print_r(implode(",\n",$output),1).']';
$output = json_encode($output);
The JQPlot code is:
<script type="text/javascript">
$(document).ready(function(){
var line1 = "<?php echo $outputString; ?>";
var plot1 = $.jqplot('chart1', [line1], {
title: 'Volume of questionnaires completed',
series:[{renderer:$.jqplot.BarRenderer}],
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
tickOptions: {
angle: -30,
fontSize: '10pt'
}
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
}
});
});
</script>
<div id="chart1" style="height:300px; width:500px;"></div>
<?php echo "<h3>";
echo $output;
echo "<br>";
echo $outputString;
echo "</h3>";?>
I have been struggling with this for quite some time so if anyone can fix this I would be hugely appreciative.
Thanks Maudise