I'm not very familiar with JavaScript but for a project that I'm working on, I need to draw a graph using some input from the db. Can you help me out with the transfer of the php values to the javascript. I just want to draw a pie chart using the data from the db.
<div id="pie" style="width:250px;height:250px;">
<?php
$k=0;
if (isset($distrib)){
foreach($distrib as $row){
echo $distrib[$k]['lang'];
echo $distrib[$k]['NumArt'];
$k++;
}
}
?>
<script class="code" type="text/javascript">
$(document).ready(function() {
var data = [];
var plot1 = jQuery.jqplot('pie', [data], {
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: {
show: false,
location: 'e'
}
});
});
</script>
EDIT
I'm still struggling with this issue. These js charts are killing me.
So here is an additional question that will hopefully end my misery
if (isset($distrib)){
foreach($distrib as $row){
$p[] = $distrib[$k]['langName'];
$s[] = $distrib[$k]['lang'];
$q[] = $distrib[$k]['NumArt'];
$k++;
}}
?><?php $c = array_combine($p, $q); ?>
<script class="code" type="text/javascript">$(document).ready(function(){
<?php echo "var s1 = [".implode($c, ",")."];" ?>
var plot3 = $.jqplot('pie', [s1], {
Basically at the moment the chart is printing out numArt, but it does not print the langName which i want. Lang name stores languages in their native alphabet which means anything from arabic to Zulu. I tried using JSON with no success (i totally lack knowledge in that area). My d/encoding was messed up so I left that path.
My goal is to render a chart which has the language's name and the amount of articles for that language.
So here is the print_r from
$p
Array ( [0] => none [1] => Catal [2] => français [3] => Malti [4] => português [5] => Kiswahili [6] => isiZulu [7] => English )
and $q Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 2 [4] => 1 [5] => 1 [6] => 1 [7] => 1 )
and the combined $c Array ( [none] => 1 [Catal] => 1 [français] => 1 [Malti] => 2 [português] => 1 [Kiswahili] => 1 [isiZulu] => 1 [English] => 1 )
In the end I need s1 to be something along these lines
[['none',1],['français',1],['Malti',1]]