Fix: better with json_encode

This commit is contained in:
Regis Houssin 2011-11-20 15:25:08 +01:00
parent 666e850d72
commit 065d7996f5
9 changed files with 188 additions and 216 deletions

View File

@ -178,10 +178,10 @@ if ($conf->use_javascript_ajax)
*/ */
$dataseries=array(); $dataseries=array();
$dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'values'=>array(round($SommeB))); $dataseries[]=array('label'=>$langs->trans("MenuMembersNotUpToDate"),'data'=>round($SommeB));
$dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'values'=>array(round($SommeC))); $dataseries[]=array('label'=>$langs->trans("MenuMembersUpToDate"),'data'=>round($SommeC));
$dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'values'=>array(round($SommeD))); $dataseries[]=array('label'=>$langs->trans("MembersStatusResiliated"),'data'=>round($SommeD));
$dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'values'=>array(round($SommeA))); $dataseries[]=array('label'=>$langs->trans("MembersStatusToValid"),'data'=>round($SommeA));
$data=array('series'=>$dataseries); $data=array('series'=>$dataseries);
dol_print_graph('stats',300,180,$data,1,'pie',1); dol_print_graph('stats',300,180,$data,1,'pie',1);
print '</td></tr>'; print '</td></tr>';

View File

@ -121,7 +121,7 @@ if ($resql)
$listofstatus=array(0,1,2,3,4); $listofstatus=array(0,1,2,3,4);
foreach ($listofstatus as $status) foreach ($listofstatus as $status)
{ {
$dataseries[]=array('label'=>$propalstatic->LibStatut($status,1),'values'=>array(0=>(isset($vals[$status])?$vals[$status]:0))); $dataseries[]=array('label'=>$propalstatic->LibStatut($status,1),'data'=>(isset($vals[$status])?$vals[$status]:0));
if (! $conf->use_javascript_ajax) if (! $conf->use_javascript_ajax)
{ {
$var=!$var; $var=!$var;

View File

@ -121,7 +121,7 @@ if ($resql)
$bool=false; $bool=false;
foreach ($listofstatus as $status) foreach ($listofstatus as $status)
{ {
$dataseries[]=array('label'=>$commandestatic->LibStatut($status,$bool,1),'values'=>array(0=>(isset($vals[$status.$bool])?$vals[$status.$bool]:0))); $dataseries[]=array('label'=>$commandestatic->LibStatut($status,$bool,1),'data'=>(isset($vals[$status.$bool])?$vals[$status.$bool]:0));
if ($status==3 && $bool==false) $bool=true; if ($status==3 && $bool==false) $bool=true;
else $bool=false; else $bool=false;
} }

View File

@ -105,7 +105,7 @@ print "</tr>\n";
$listoftype=$tripandexpense_static->listOfTypes(); $listoftype=$tripandexpense_static->listOfTypes();
foreach ($listoftype as $code => $label) foreach ($listoftype as $code => $label)
{ {
$dataseries[]=array('label'=>$label,'values'=>array(0=>(isset($nb[$code])?$nb[$code]:0))); $dataseries[]=array('label'=>$label,'data'=>(isset($nb[$code])?$nb[$code]:0));
} }
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax)

View File

@ -87,7 +87,7 @@ print "</tr>\n";
$listofstatus=array(0,1,-1,2); $listofstatus=array(0,1,-1,2);
foreach ($listofstatus as $status) foreach ($listofstatus as $status)
{ {
$dataseries[]=array('label'=>$donstatic->LibStatut($status,1),'values'=>array(0=>(isset($nb[$status])?$nb[$status]:0))); $dataseries[]=array('label'=>$donstatic->LibStatut($status,1),'data'=>(isset($nb[$status])?$nb[$status]:0));
} }
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax)

View File

@ -180,7 +180,7 @@ $var=true;
$listofstatus=array(0,4,4,5); $bool=false; $listofstatus=array(0,4,4,5); $bool=false;
foreach($listofstatus as $status) foreach($listofstatus as $status)
{ {
$dataseries[]=array('label'=>$staticcontratligne->LibStatut($status,1,($bool?1:0)),'values'=>array(0=>($nb[$status.$bool]?$nb[$status.$bool]:0))); $dataseries[]=array('label'=>$staticcontratligne->LibStatut($status,1,($bool?1:0)),'data'=>($nb[$status.$bool]?$nb[$status.$bool]:0));
if (! $conf->use_javascript_ajax) if (! $conf->use_javascript_ajax)
{ {
$var=!$var; $var=!$var;

View File

@ -1500,14 +1500,16 @@ function dolibarr_trunc($string,$size=40,$trunc='right',$stringencoding='')
/** /**
* Show a javascript graph * Show a javascript graph
* @param htmlid Html id name *
* @param width Width in pixel * @param string $htmlid Html id name
* @param height Height in pixel * @param int $width Width in pixel
* @param data Data array * @param int $height Height in pixel
* @param showlegend 1 to show legend, 0 otherwise * @param array $data Data array
* @param type Type of graph ('pie', 'barline') * @param int $showlegend 1 to show legend, 0 otherwise
* @param showpercent Show percent (with type='pie' only) * @param string $type Type of graph ('pie', 'barline')
* @param url Param to add an url to click values * @param int $showpercent Show percent (with type='pie' only)
* @param string $url Param to add an url to click values
* @return void
*/ */
function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',$showpercent=0,$url='') function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',$showpercent=0,$url='')
{ {
@ -1542,24 +1544,14 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
// 'seriestype'=>array('bar','line',...), // 'seriestype'=>array('bar','line',...),
// 'seriescolor'=>array(0=>'#999999',1=>'#999999',...) // 'seriescolor'=>array(0=>'#999999',1=>'#999999',...)
// 'xlabel'=>array(0=>labelx1,1=>labelx2,...)); // 'xlabel'=>array(0=>labelx1,1=>labelx2,...));
// serieX is array('label'=>'label', values=>array(0=>val)) // serieX is array('label'=>'label', data=>val)
print ' print '
<script type="text/javascript"> <script type="text/javascript">
jQuery(function () { $(function () {
var data = ['."\n"; var data = '.json_encode($data['series']).';
$i=0;
foreach($data['series'] as $serie)
{
//print '{ label: "'.($showlegend?$serie['values'][0]:$serie['label'].'<br>'.$serie['values'][0]).'", data: '.$serie['values'][0].' }';
print '{ label: "'.dol_escape_js($serie['label']).'", data: '.$serie['values'][0].' }';
if ($i < count($data['series'])) print ',';
print "\n";
$i++;
}
print '];
function plotWithOptions() { function plotWithOptions() {
jQuery.plot(jQuery("#'.$htmlid.'"), data, $.plot($("#'.$htmlid.'"), data,
{ {
series: { series: {
pie: { pie: {
@ -1585,26 +1577,17 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
color: \'#000000\' color: \'#000000\'
} }
} }
} }, }
},
zoom: { zoom: {
interactive: true interactive: true
}, },
pan: { pan: {
interactive: true interactive: true
}, },';
';
$i=0; $outputserie=0;
if (count($datacolor)) if (count($datacolor))
{ {
print 'colors: ['; print 'colors: '.(! empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).',';
foreach($datacolor as $val)
{
if ($outputserie > 0) print ',';
print '"'.(empty($data['seriescolor'][$i])?$val:$data['seriescolor'][$i]).'"';
$outputserie++;
$i++;
}
print '], ';
} }
print 'legend: {show: '.($showlegend?'true':'false').', position: \'ne\' } print 'legend: {show: '.($showlegend?'true':'false').', position: \'ne\' }
}); });
@ -1622,7 +1605,7 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
// serieX is array('label'=>'label', values=>array(0=>y1,1=>y2,...)) with same nb of value than into xlabel // serieX is array('label'=>'label', values=>array(0=>y1,1=>y2,...)) with same nb of value than into xlabel
print ' print '
<script type="text/javascript"> <script type="text/javascript">
jQuery(function () { $(function () {
var data = ['; var data = [';
$i=1; $outputserie=0; $i=1; $outputserie=0;
foreach($data['series'] as $serie) foreach($data['series'] as $serie)
@ -1638,8 +1621,7 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
$j++; $j++;
} }
print ']}'."\n"; print ']}'."\n";
$outputserie++; $outputserie++; $i++;
$i++;
} }
if ($outputserie) print ', '; if ($outputserie) print ', ';
//print ']; //print '];
@ -1658,8 +1640,7 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
$j++; $j++;
} }
print ']}'."\n"; print ']}'."\n";
$outputserie++; $outputserie++; $i++;
$i++;
} }
print ']; print '];
var dataticks = ['; var dataticks = [';
@ -1673,7 +1654,7 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
print ']; print '];
function plotWithOptions() { function plotWithOptions() {
jQuery.plot(jQuery("#'.$htmlid.'"), data, $.plot(jQuery("#'.$htmlid.'"), data,
{ {
series: { series: {
stack: 0 stack: 0
@ -1683,22 +1664,13 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',
}, },
pan: { pan: {
interactive: true interactive: true
}, },';
';
if (count($datacolor)) if (count($datacolor))
{ {
print 'colors: ['; print 'colors: '.json_encode($datacolor).',';
$j=0;
foreach($datacolor as $val)
{
print '"'.$val.'"';
if ($j < count($datacolor)) print ',';
$j++;
}
print '], ';
} }
print 'legend: {show: '.($showlegend?'true':'false').'}, print 'legend: {show: '.($showlegend?'true':'false').'},
xaxis: {ticks: dataticks}, xaxis: {ticks: dataticks}
}); });
} }
plotWithOptions(); plotWithOptions();

View File

@ -118,7 +118,7 @@ if ($resql)
print "</tr>\n"; print "</tr>\n";
foreach (array(0,1,2,3,4,5,6) as $statut) foreach (array(0,1,2,3,4,5,6) as $statut)
{ {
$dataseries[]=array('label'=>$commandestatic->LibStatut($statut,1),'values'=>array(0=>(isset($vals[$statut])?$vals[$statut]:0))); $dataseries[]=array('label'=>$commandestatic->LibStatut($statut,1),'data'=>(isset($vals[$statut])?$vals[$statut]:0));
if (! $conf->use_javascript_ajax) if (! $conf->use_javascript_ajax)
{ {
$var=!$var; $var=!$var;

View File

@ -108,9 +108,9 @@ if ($conf->use_javascript_ajax && ((round($third['prospect'])?1:0)+(round($third
{ {
print '<tr><td align="center">'; print '<tr><td align="center">';
$dataseries=array(); $dataseries=array();
if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[]=array('label'=>$langs->trans("Prospects"),'values'=>array(round($third['prospect']))); if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[]=array('label'=>$langs->trans("Prospects"),'data'=>round($third['prospect']));
if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Customers"),'values'=>array(round($third['customer']))); if ($conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Customers"),'data'=>round($third['customer']));
if ($conf->fournisseur->enabled && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Suppliers"),'values'=>array(round($third['supplier']))); if ($conf->fournisseur->enabled && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Suppliers"),'data'=>round($third['supplier']));
$data=array('series'=>$dataseries); $data=array('series'=>$dataseries);
dol_print_graph('stats',300,180,$data,1,'pie',0); dol_print_graph('stats',300,180,$data,1,'pie',0);
print '</td></tr>'; print '</td></tr>';