42 public $type = array();
43 public $mode =
'side';
44 private $_library =
'chart';
49 public $cssprefix =
'';
62 public $SetShading = 0;
64 public $horizTickIncrement = -1;
65 public $SetNumXTicks = -1;
66 public $labelInterval = -1;
68 public $hideXGrid =
false;
69 public $hideYGrid =
false;
71 public $Legend = array();
72 public $LegendWidthMin = 0;
73 public $showlegend = 1;
74 public $showpointvalue = 1;
75 public $showpercent = 0;
86 public $bgcolorgrid = array(255, 255, 255);
89 private $stringtoshow;
100 global $theme_bordercolor, $theme_datacolor, $theme_bgcolor;
102 $this->bordercolor = array(235, 235, 224);
103 $this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220));
104 $this->bgcolor = array(235, 235, 224);
106 $color_file = DOL_DOCUMENT_ROOT .
'/theme/' . $conf->theme .
'/theme_vars.inc.php';
107 if (is_readable($color_file)) {
108 include_once $color_file;
109 if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor;
110 if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor;
111 if (isset($theme_bgcolor)) $this->bgcolor = $theme_bgcolor;
115 $this->_library = $library;
116 if ($this->_library ==
'auto') {
117 $this->_library = (empty($conf->global->MAIN_JS_GRAPH) ?
'chart' : $conf->global->MAIN_JS_GRAPH);
132 $this->horizTickIncrement = $xi;
160 $this->labelInterval = $x;
174 $this->hideXGrid = $bool;
188 $this->hideYGrid = $bool;
202 $this->YLabel = $label;
228 $this->title = $title;
255 $this->datacolor = $datacolor;
282 $this->Legend = $legend;
295 $this->LegendWidthMin = $legendwidthmin;
308 $this->MaxValue = $max;
320 return $this->MaxValue;
333 $this->MinValue = $min;
345 return $this->MinValue;
384 $this->cssprefix = $s;
396 unset($this->bgcolor);
408 unset($this->bgcolorgrid);
429 $this->showlegend = $showlegend;
440 $this->showpointvalue = $showpointvalue;
451 $this->showpercent = $showpercent;
466 global $theme_bgcolor, $theme_bgcoloronglet;
468 if (!is_array($bg_color)) {
469 if ($bg_color ==
'onglet') {
471 $this->bgcolor = $theme_bgcoloronglet;
473 $this->bgcolor = $theme_bgcolor;
476 $this->bgcolor = $bg_color;
490 global $theme_bgcolor, $theme_bgcoloronglet;
492 if (!is_array($bg_colorgrid)) {
493 if ($bg_colorgrid ==
'onglet') {
495 $this->bgcolorgrid = $theme_bgcoloronglet;
497 $this->bgcolorgrid = $theme_bgcolor;
500 $this->bgcolorgrid = $bg_colorgrid;
513 unset($this->datacolor);
525 if (!is_array($this->data))
return 0;
530 $nblines = count($this->data);
531 $nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
533 for ($j = 0; $j < $nblines; $j++) {
534 for ($i = 0; $i < $nbvalues; $i++) {
535 $vals[$k] = $this->data[$j][$i + 1];
552 if (!is_array($this->data))
return 0;
557 $nblines = count($this->data);
558 $nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
560 for ($j = 0; $j < $nblines; $j++) {
561 for ($i = 0; $i < $nbvalues; $i++) {
562 $vals[$k] = $this->data[$j][$i + 1];
580 if ($max != 0) $max++;
583 for ($i = 0; $i < ($size - 1); $i++) {
588 if (is_numeric($max)) $res = ceil($max / $factor) * $factor;
604 if ($min ==
'') $min = 0;
605 if ($min != 0) $min--;
608 for ($i = 0; $i < ($size - 1); $i++) {
612 $res = floor($min / $factor) * $factor;
625 public function draw($file, $fileurl =
'')
628 $this->error =
"Call to draw method was made with empty value for parameter file.";
629 dol_syslog(get_class($this) .
"::draw " . $this->error, LOG_ERR);
632 if (!is_array($this->data)) {
633 $this->error =
"Call to draw method was made but SetData was not called or called with an empty dataset for parameters";
634 dol_syslog(get_class($this) .
"::draw " . $this->error, LOG_ERR);
637 if (count($this->data) < 1) {
638 $this->error =
"Call to draw method was made but SetData was is an empty dataset";
639 dol_syslog(get_class($this) .
"::draw " . $this->error, LOG_WARNING);
641 $call =
"draw_" . $this->_library;
642 call_user_func_array(array($this, $call), array($file, $fileurl));
665 global $conf, $langs;
667 dol_syslog(get_class($this) .
"::draw_jflot this->type=" . join(
',', $this->
type) .
" this->MaxValue=" . $this->MaxValue);
669 if (empty($this->width) && empty($this->height)) {
670 print 'Error width or height not set';
676 if (is_array($this->data) && is_array($this->data[0])) {
677 $nblot = count($this->data[0]) - 1;
679 if ($nblot < 0)
dol_syslog(
'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
689 $serie[$i] =
"var d" . $i .
" = [];\n";
693 foreach ($this->data as $valarray)
695 $legends[$x] = $valarray[0];
696 $values[$x] = (is_numeric($valarray[$i + 1]) ? $valarray[$i + 1] : null);
700 if (isset($this->
type[$firstlot]) && in_array($this->
type[$firstlot], array(
'pie',
'piesemicircle',
'polar'))) {
701 foreach ($values as $x => $y) {
702 if (isset($y)) $serie[$i] .=
'd' . $i .
'.push({"label":"' .
dol_escape_js($legends[$x]) .
'", "data":' . $y .
'});' .
"\n";
705 foreach ($values as $x => $y) {
706 if (isset($y)) $serie[$i] .=
'd' . $i .
'.push([' . $x .
', ' . $y .
']);' .
"\n";
715 $this->stringtoshow =
'<!-- Build using jflot -->' .
"\n";
716 if (!empty($this->title)) $this->stringtoshow .=
'<div class="center dolgraphtitle' . (empty($this->cssprefix) ?
'' :
' dolgraphtitle' . $this->cssprefix) .
'">' . $this->title .
'</div>';
717 if (!empty($this->shownographyet)) {
718 $this->stringtoshow .=
'<div style="width:' . $this->width .
'px;height:' . $this->height .
'px;" class="nographyet"></div>';
719 $this->stringtoshow .=
'<div class="nographyettext margintoponly">' . $langs->trans(
"NotEnoughDataYet") .
'...</div>';
724 $dolxaxisvertical =
'';
725 if (count($this->data) > 20) $dolxaxisvertical =
'dol-xaxis-vertical';
726 $this->stringtoshow .=
'<div id="placeholder_' . $tag .
'" style="width:' . $this->width .
'px;height:' . $this->height .
'px;" class="dolgraph' . (empty($dolxaxisvertical) ?
'' :
' ' . $dolxaxisvertical) . (empty($this->cssprefix) ?
'' :
' dolgraph' . $this->cssprefix) .
' center"></div>' .
"\n";
728 $this->stringtoshow .=
'<script id="' . $tag .
'">' .
"\n";
729 $this->stringtoshow .=
'$(function () {' .
"\n";
732 $this->stringtoshow .=
'<!-- No series of data -->' .
"\n";
734 while ($i < $nblot) {
735 $this->stringtoshow .=
'<!-- Serie ' . $i .
' -->' .
"\n";
736 $this->stringtoshow .= $serie[$i] .
"\n";
740 $this->stringtoshow .=
"\n";
743 if (isset($this->
type[$firstlot]) && in_array($this->
type[$firstlot], array(
'pie',
'piesemicircle',
'polar'))) {
744 $datacolor = array();
745 foreach ($this->datacolor as $val) {
746 if (is_array($val)) $datacolor[] =
"#" . sprintf(
"%02x%02x%02x", $val[0], $val[1], $val[2]);
747 else $datacolor[] =
"#" . str_replace(array(
'#',
'-'),
'', $val);
751 $showlegend = $this->showlegend;
752 $showpointvalue = $this->showpointvalue;
753 $showpercent = $this->showpercent;
755 $this->stringtoshow .=
'
756 function plotWithOptions_' . $tag .
'() {
757 $.plot($("#placeholder_' . $tag .
'"), d0,
763 ' . ($this->combine ?
'
765 threshold: ' . $this->combine .
'
770 formatter: function(label, series) {
771 var percent=Math.round(series.percent);
772 var number=series.data[0][1];
774 $this->stringtoshow .=
'<span style="font-size:8pt;text-align:center;padding:2px;color:black;">';
775 if ($urltemp) $this->stringtoshow .=
'<a style="color: #FFFFFF;" border="0" href="' . $urltemp .
'">';
776 $this->stringtoshow .=
'\'+
';
777 $this->stringtoshow .= ($showlegend ? '' : 'label+\
' \'+');
778 $this->stringtoshow .= ($showpointvalue ?
'number+' :
'');
779 $this->stringtoshow .= ($showpercent ?
'\'<br/>\
'+percent+\'%\'+' :
'');
780 $this->stringtoshow .=
'\'';
781 if ($urltemp) $this->stringtoshow .=
'</a>';
782 $this->stringtoshow .=
'</span>\';
797 if (count($datacolor)) {
798 $this->stringtoshow .=
'colors: ' . (!empty(
$data[
'seriescolor']) ? json_encode(
$data[
'seriescolor']) : json_encode($datacolor)) .
',';
800 $this->stringtoshow .=
'legend: {show: ' . ($showlegend ?
'true' :
'false') .
', position: \'ne\' }
808 $this->stringtoshow .=
'
809 function showTooltip_' . $tag .
'(x, y, contents) {
810 $(\'<div class="graph-tooltip-inner" id="tooltip_' . $tag .
'">\' + contents + \'</div>\').css({
811 position: \'absolute\',
815 border: \'1px solid #000\',
817 \'background-color\': \'#000\',
819 \'font-weight\': \'bold\',
822 }).appendTo("body").fadeIn(100);
825 var previousPoint = null;
826 $("#placeholder_' . $tag .
'").bind("plothover", function (event, pos, item) {
827 $("#x").text(pos.x.toFixed(2));
828 $("#y").text(pos.y.toFixed(2));
831 if (previousPoint != item.dataIndex) {
832 previousPoint = item.dataIndex;
834 $("#tooltip").remove();
835 /* console.log(item); */
836 var x = item.datapoint[0].toFixed(2);
837 var y = item.datapoint[1].toFixed(2);
838 var z = item.series.xaxis.ticks[item.dataIndex].label;
840 if ($this->showpointvalue > 0) $this->stringtoshow .=
'
841 showTooltip_' . $tag .
'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
843 $this->stringtoshow .=
'
847 $("#tooltip_' . $tag .
'").remove();
848 previousPoint = null;
853 $this->stringtoshow .=
'var stack = null, steps = false;' .
"\n";
855 $this->stringtoshow .=
'function plotWithOptions_' . $tag .
'() {' .
"\n";
856 $this->stringtoshow .=
'$.plot($("#placeholder_' . $tag .
'"), [ ' .
"\n";
858 while ($i < $nblot) {
859 if ($i > $firstlot) $this->stringtoshow .=
', ' .
"\n";
860 $color = sprintf(
"%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
861 $this->stringtoshow .=
'{ ';
862 if (!isset($this->
type[$i]) || $this->
type[$i] ==
'bars') {
864 if ($i == $firstlot) $align =
'right';
865 elseif ($i == $firstlot + 1) $align =
'center';
866 else $align =
'left';
867 $this->stringtoshow .=
'bars: { lineWidth: 1, show: true, align: "' . $align .
'", barWidth: 0.45 }, ';
868 }
else $this->stringtoshow .=
'bars: { lineWidth: 1, show: true, align: "' . ($i == $firstlot ?
'center' :
'left') .
'", barWidth: 0.5 }, ';
870 if (isset($this->
type[$i]) && ($this->
type[$i] ==
'lines' || $this->
type[$i] ==
'linesnopoint')) $this->stringtoshow .=
'lines: { show: true, fill: false }, points: { show: ' . ($this->
type[$i] ==
'linesnopoint' ?
'false' :
'true') .
' }, ';
871 $this->stringtoshow .=
'color: "#' . $color .
'", label: "' . (isset($this->Legend[$i]) ?
dol_escape_js($this->Legend[$i]) :
'') .
'", data: d' . $i .
' }';
875 $this->stringtoshow .=
"\n" .
' ], { series: { shadowSize: 0, stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6, fillColor: { colors: [{opacity: 0.9 }, {opacity: 0.85}] }} }' .
"\n";
878 $this->stringtoshow .=
', xaxis: { ticks: [' .
"\n";
880 foreach ($this->data as $key => $valarray) {
881 if ($x > 0) $this->stringtoshow .=
', ' .
"\n";
882 $this->stringtoshow .=
' [' . $x .
', "' . $valarray[0] .
'"]';
885 $this->stringtoshow .=
'] }' .
"\n";
888 $this->stringtoshow .=
', yaxis: { min: ' . $this->MinValue .
', max: ' . ($this->MaxValue) .
' }' .
"\n";
891 $color1 = sprintf(
"%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]);
892 $color2 = sprintf(
"%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
893 $this->stringtoshow .=
', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 .
'", "#' . $color2 .
'"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }' .
"\n";
894 $this->stringtoshow .=
'});' .
"\n";
895 $this->stringtoshow .=
'}' .
"\n";
898 $this->stringtoshow .=
'plotWithOptions_' . $tag .
'();' .
"\n";
899 $this->stringtoshow .=
'});' .
"\n";
900 $this->stringtoshow .=
'</script>' .
"\n";
924 global $conf, $langs;
926 dol_syslog(get_class($this) .
"::draw_chart this->type=" . join(
',', $this->
type) .
" this->MaxValue=" . $this->MaxValue);
928 if (empty($this->width) && empty($this->height)) {
929 print 'Error width or height not set';
933 $showlegend = $this->showlegend;
937 if (is_array($this->data)) {
938 foreach ($this->data as $valarray)
940 $nblot = max($nblot, count($valarray) - 1);
944 if ($nblot < 0)
dol_syslog(
'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
950 $arrayofgroupslegend = array();
961 foreach ($this->data as $valarray)
963 $legends[$x] = (array_key_exists(
'label', $valarray) ? $valarray[
'label'] : $valarray[0]);
964 $array_of_ykeys = array_keys($valarray);
966 $tmpykey = explode(
'_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3);
967 if (!empty($tmpykey[2]) || $tmpykey[2] ==
'0') {
968 $tmpvalue = (array_key_exists(
'y_' . $tmpykey[1] .
'_' . $tmpykey[2], $valarray) ? $valarray[
'y_' . $tmpykey[1] .
'_' . $tmpykey[2]] : $valarray[$i + 1]);
969 $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
970 $arrayofgroupslegend[$i] = array(
971 'stacknum' => $tmpykey[1],
972 'legend' => $this->Legend[$tmpykey[1]],
973 'legendwithgroup' => $this->Legend[$tmpykey[1]] .
' - ' . $tmpykey[2]
976 $tmpvalue = (array_key_exists(
'y_' . $i, $valarray) ? $valarray[
'y_' . $i] : $valarray[$i + 1]);
978 $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
984 foreach ($values as $x => $y) {
986 $serie[$i] .= ($j > 0 ?
", " :
"") . $y;
988 $serie[$i] .= ($j > 0 ?
", " :
"") .
'null';
1001 $this->stringtoshow =
'<!-- Build using chart -->' .
"\n";
1002 if (!empty($this->title)) $this->stringtoshow .=
'<div class="center dolgraphtitle' . (empty($this->cssprefix) ?
'' :
' dolgraphtitle' . $this->cssprefix) .
'">' . $this->title .
'</div>';
1003 if (!empty($this->shownographyet)) {
1004 $this->stringtoshow .=
'<div style="width:' . $this->width . (strpos($this->width,
'%') > 0 ?
'' :
'px') .
'; height:' . $this->height .
'px;" class="nographyet"></div>';
1005 $this->stringtoshow .=
'<div class="nographyettext margintoponly">' . $langs->trans(
"NotEnoughDataYet") .
'...</div>';
1010 $dolxaxisvertical =
'';
1011 if (count($this->data) > 20) $dolxaxisvertical =
'dol-xaxis-vertical';
1013 $cssfordiv =
'dolgraphchart';
1014 if (isset($this->
type[$firstlot])) $cssfordiv .=
' dolgraphchar' . $this->
type[$firstlot];
1015 $this->stringtoshow .=
'<div id="placeholder_' . $tag .
'" style="min-height: ' . $this->height . (strpos($this->height,
'%') > 0 ?
'' :
'px') .
'; width:' . $this->width . (strpos($this->width,
'%') > 0 ?
'' :
'px') .
';" class="' . $cssfordiv .
' dolgraph' . (empty($dolxaxisvertical) ?
'' :
' ' . $dolxaxisvertical) . (empty($this->cssprefix) ?
'' :
' dolgraph' . $this->cssprefix) .
' center"><canvas id="canvas_' . $tag .
'"></canvas></div>' .
"\n";
1017 $this->stringtoshow .=
'<script id="' . $tag .
'">' .
"\n";
1020 $this->stringtoshow .=
'<!-- No series of data -->';
1022 while ($i < $nblot) {
1028 $this->stringtoshow .=
"\n";
1031 if (isset($this->
type[$firstlot]) && (in_array($this->
type[$firstlot], array(
'pie',
'polar',
'piesemicircle')))) {
1032 $type = $this->
type[$firstlot];
1033 $this->stringtoshow .=
'var options = {' .
"\n";
1034 $legendMaxLines = 0;
1035 if (empty($showlegend)) {
1036 $this->stringtoshow .=
'legend: { display: false }, ';
1038 $this->stringtoshow .=
'legend: { position: \'' . ($showlegend == 2 ?
'right' :
'top') .
'\'';
1039 if (!empty($legendMaxLines)) {
1040 $this->stringtoshow .=
', maxLines: ' . $legendMaxLines .
'';
1042 $this->stringtoshow .=
' }, ' .
"\n";
1045 if ($this->
type[$firstlot] ==
'piesemicircle') {
1046 $this->stringtoshow .=
'circumference: Math.PI,' .
"\n";
1047 $this->stringtoshow .=
'rotation: -Math.PI,' .
"\n";
1049 $this->stringtoshow .=
'elements: { arc: {' .
"\n";
1051 $this->stringtoshow .=
'backgroundColor: [';
1053 $foundnegativecolor = 0;
1054 foreach ($legends as $val)
1056 if ($i > 0) $this->stringtoshow .=
', ' .
"\n";
1057 if (is_array($this->datacolor[$i])) $color =
'rgb(' . $this->datacolor[$i][0] .
', ' . $this->datacolor[$i][1] .
', ' . $this->datacolor[$i][2] .
')';
1059 $tmp = str_replace(
'#',
'', $this->datacolor[$i]);
1060 if (strpos($tmp,
'-') !==
false) {
1061 $foundnegativecolor++;
1063 }
else $color =
"#" . $tmp;
1065 $this->stringtoshow .=
"'" . $color .
"'";
1068 $this->stringtoshow .=
'], ' .
"\n";
1070 if ($foundnegativecolor) {
1071 $this->stringtoshow .=
'borderColor: [';
1073 foreach ($legends as $val)
1075 if ($i > 0) $this->stringtoshow .=
', ' .
"\n";
1076 if (is_array($this->datacolor[$i])) $color =
'null';
1078 $tmp = str_replace(
'#',
'', $this->datacolor[$i]);
1079 if (strpos($tmp,
'-') !==
false) $color =
'#' . str_replace(
'-',
'', $tmp);
1080 else $color =
'null';
1082 $this->stringtoshow .= ($color ==
'null' ?
"'rgba(0,0,0,0.2)'" :
"'" . $color .
"'");
1085 $this->stringtoshow .=
']';
1087 $this->stringtoshow .=
'} } };' .
"\n";
1089 $this->stringtoshow .=
'
1090 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1091 var chart = new Chart(ctx, {
1092 // The type of chart we want to create
1093 type: \'' . (in_array($type, array(
'pie',
'piesemicircle')) ?
'doughnut' :
'polarArea') .
'\',
1100 foreach ($legends as $val) // Loop on each serie
1102 if ($i > 0) $this->stringtoshow .= ',
';
1103 $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'";
1107 $this->stringtoshow .= '],
1111 while ($i < $nblot) // Loop on each serie
1113 $color = 'rgb(
' . $this->datacolor[$i][0] . ',
' . $this->datacolor[$i][1] . ',
' . $this->datacolor[$i][2] . ')
';
1114 //$color = (!empty($data['seriescolor
']) ? json_encode($data['seriescolor
']) : json_encode($datacolor));
1116 if ($i > 0) $this->stringtoshow .= ',
' . "\n";
1117 $this->stringtoshow .= '{
' . "\n";
1118 //$this->stringtoshow .= 'borderColor: \
''.$color.
'\',
';
1119 //$this->stringtoshow .= 'backgroundColor: \
''.$color.
'\',
';
1120 $this->stringtoshow .= ' data: [
' . $serie[$i] . ']
';
1121 $this->stringtoshow .= '}
' . "\n";
1124 $this->stringtoshow .= ']
' . "\n";
1125 $this->stringtoshow .= '}
' . "\n";
1126 $this->stringtoshow .= '});
' . "\n";
1128 // Other cases, graph of type 'bars
', 'lines
', 'linesnopoint
'
1133 if ($file == 'idgraphleadfunnel
') $isfunnel = true;
1135 if (!isset($this->type[$firstlot]) || $this->type[$firstlot] == 'bars
') $type = 'bar
';
1136 if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'horizontalbars
') $type = 'horizontalBar
';
1137 if (isset($this->type[$firstlot]) && ($this->type[$firstlot] == 'lines
' || $this->type[$firstlot] == 'linesnopoint
')) $type = 'line
';
1139 $this->stringtoshow .= 'var options = { maintainAspectRatio:
false, aspectRatio: 2.5,
';
1140 if (empty($showlegend)) {
1141 $this->stringtoshow .= 'legend: { display:
false },
';
1143 $this->stringtoshow .= 'scales: { xAxes: [{
';
1144 if ($isfunnel) { // FIXME Remove isfunnel by introducing a method hideXValues() on dolgraph
1145 $this->stringtoshow .= ' ticks: { display:
false }, display:
true,
';
1147 //$this->stringtoshow .= 'type: \
'time\', ';
1148 $this->stringtoshow .=
'distribution: \'linear\'';
1149 if ($type ==
'bar' && count($arrayofgroupslegend) > 0) {
1150 $this->stringtoshow .=
', stacked: true';
1152 $this->stringtoshow .=
' }]';
1153 $this->stringtoshow .=
', yAxes: [{ ticks: { beginAtZero: true }';
1154 if ($type ==
'bar' && count($arrayofgroupslegend) > 0) {
1155 $this->stringtoshow .=
', stacked: true';
1157 $this->stringtoshow .=
' }] }';
1160 $this->stringtoshow .=
', tooltips: { mode: \'nearest\',
1162 title: function(tooltipItem, data) {
1163 return data.datasets[tooltipItem[0].datasetIndex].label;
1165 label: function(tooltipItem, data) {
1166 return data.datasets[tooltipItem.datasetIndex].data[0][1];
1171 $this->stringtoshow .=
'};';
1172 $this->stringtoshow .=
'
1173 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1174 var chart = new Chart(ctx, {
1175 // The type of chart we want to create
1176 type: \'' . $type .
'\',
1184 foreach ($legends as $val) // Loop on each serie
1186 if ($i > 0) $this->stringtoshow .= ',
';
1187 $this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'";
1192 //var_dump($arrayofgroupslegend);
1194 $this->stringtoshow .= '],
1197 global $theme_datacolor;
1198 //var_dump($arrayofgroupslegend);
1199 $i = 0; $iinstack = 0;
1201 while ($i < $nblot) // Loop on each serie
1203 $foundnegativecolor = 0;
1204 $usecolorvariantforgroupby = 0;
1205 // We used a 'group by
' and we have too many colors so we generated color variants per
1206 if (is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by.
1207 $nbofcolorneeds = count($arrayofgroupslegend);
1208 $nbofcolorsavailable = count($theme_datacolor);
1209 if ($nbofcolorneeds > $nbofcolorsavailable) {
1210 $usecolorvariantforgroupby = 1;
1213 $textoflegend = $arrayofgroupslegend[$i]['legendwithgroup
'];
1215 $textoflegend = $this->Legend[$i];
1218 if ($usecolorvariantforgroupby) {
1219 $newcolor = $this->datacolor[$arrayofgroupslegend[$i]['stacknum
']];
1220 // If we change the stack
1221 if ($oldstacknum == -1 || $arrayofgroupslegend[$i]['stacknum
'] != $oldstacknum) {
1225 //var_dump($iinstack);
1227 // Change color with offset of $$iinstack
1228 //var_dump($newcolor);
1229 if ($iinstack % 2) { // We increase agressiveness of reference color for color 2, 4, 6, ...
1230 $ratio = min(95, 10 + 10 * $iinstack); // step of 20
1231 $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10
1232 } else { // We decrease agressiveness of reference color for color 3, 5, 7, ..
1233 $ratio = max(-100, -15 * $iinstack + 10); // step of -20
1234 $brightnessratio = min(90, 10 * $iinstack); // step of 20
1236 //var_dump('Color
'.($iinstack+1).' :
'.$ratio.' '.$brightnessratio);
1238 $newcolor = array_values(colorHexToRgb(colorAgressiveness(colorArrayToHex($newcolor), $ratio, $brightnessratio), false, true));
1240 $oldstacknum = $arrayofgroupslegend[$i]['stacknum
'];
1242 $color = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ', 0.9)
';
1243 $bordercolor = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ')
';
1244 } else { // We do not use a 'group by
'
1246 $bordercolor == 'null
';
1247 if (is_array($this->datacolor[$i])) {
1248 $color = 'rgb(
' . $this->datacolor[$i][0] . ',
' . $this->datacolor[$i][1] . ',
' . $this->datacolor[$i][2] . ', 0.9)
'; // If datacolor is array(R, G, B)
1250 // TODO FIXME This logic must be in the caller that set $this->datacolor
1251 $tmp = str_replace('#
', '', $this->datacolor[$i]);
1252 if (strpos($tmp, '-
') !== false) {
1253 $foundnegativecolor++;
1254 $color = '#FFFFFF
'; // If $val is '-123
'
1256 $color = "#" . $tmp; // If $val is '123
' or '#123
'
1257 $bordercolor = $color;
1259 if ($foundnegativecolor) {
1260 if (is_array($this->datacolor[$i])) $color = 'null
'; // If datacolor is array(R, G, B)
1262 $tmp = str_replace('#
', '', $this->datacolor[$i]);
1263 if (strpos($tmp, '-
') !== false) $bordercolor = '#
' . str_replace('-
', '', $tmp); // If $val is '-123
'
1264 else $bordercolor = 'null
'; // If $val is '123
' or '#123
'
1268 $bordercolor == 'null
' ? "'rgba(0,0,0,0.2)
'" : "'" . $bordercolor . "'";
1270 $color = 'rgb(
'.$this->datacolor[$i][0].',
'.$this->datacolor[$i][1].',
'.$this->datacolor[$i][2].', 0.9)
';
1271 $bordercolor = $color;
1272 //$color = (!empty($data['seriescolor
']) ? json_encode($data['seriescolor
']) : json_encode($datacolor));
1276 if ($i > 0) $this->stringtoshow .= ',
';
1277 $this->stringtoshow .= "\n";
1278 $this->stringtoshow .= '{
';
1279 $this->stringtoshow .= 'dolibarrinfo: \
'y_' . $i .
'\',
';
1281 $this->stringtoshow .= 'pointStyle: \
'' . ($this->
type[$i] ==
'linesnopoint' ?
'line' :
'circle') .
'\',
';
1282 $this->stringtoshow .= 'fill:
' . ($type == 'bar
' ? 'true' : 'false') . ',
';
1284 $this->stringtoshow .= 'borderWidth: \
'2\', ';
1285 } elseif ($type ==
'bar' || $type ==
'horizontalBar') {
1286 $this->stringtoshow .=
'borderWidth: \'1\', ';
1288 $this->stringtoshow .=
'borderColor: \'' . $bordercolor .
'\',
';
1289 $this->stringtoshow .= 'backgroundColor: \
'' . $color .
'\',
';
1290 if ($arrayofgroupslegend[$i]) $this->stringtoshow .= 'stack: \
'' . $arrayofgroupslegend[$i][
'stacknum'] .
'\',
';
1291 $this->stringtoshow .='data: [
';
1293 $this->stringtoshow .= '[
'.-$serie[$i].',
'.$serie[$i].']
';
1295 $this->stringtoshow .= $serie[$i];
1297 $this->stringtoshow .=']
';
1298 $this->stringtoshow .= '}
' . "\n";
1303 $this->stringtoshow .= ']
' . "\n";
1304 $this->stringtoshow .= '}
' . "\n";
1305 $this->stringtoshow .= '});
' . "\n";
1308 $this->stringtoshow .= '</script>
' . "\n";
1317 public function total()
1320 foreach ($this->data as $valarray) // Loop on each x
1322 $value += $valarray[1];
1333 public function show($shownographyet = 0)
1337 if ($shownographyet) {
1338 $s = '<div
class=
"nographyet" style=
"width:' . (preg_match('/%/', $this->width) ? $this->width : $this->width . 'px') . '; height:' . (preg_match('/%/', $this->height) ? $this->height : $this->height . 'px') . ';"></div>
';
1339 $s .= '<div
class=
"nographyettext margintoponly">
';
1340 if (is_numeric($shownographyet)) {
1341 $s .= $langs->trans("NotEnoughDataYet") . '...
';
1343 $s .= $shownographyet . '...
';
1349 return $this->stringtoshow;
1360 public static function getDefaultGraphSizeForStats($direction, $defaultsize = '')
1364 if ($direction == 'width
')
1366 if (empty($conf->dol_optimize_smallscreen)) return ($defaultsize ? $defaultsize : '500
');
1367 else return (empty($_SESSION['dol_screen_width
']) ? '280
' : ($_SESSION['dol_screen_width
'] - 40));
1369 if ($direction == 'height
')
1371 return (empty($conf->dol_optimize_smallscreen) ? ($defaultsize ? $defaultsize : '200
') : '160
');
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
setShowPercent($showpercent)
Show percent or not.
SetCssPrefix($s)
Set shading.
setShowLegend($showlegend)
Show legend or not.
SetLegend($legend)
Set legend.
ResetBgColorGrid()
Reset bgcolorgrid.
SetMaxValue($max)
Set max value.
GetFloorMinValue()
Return min value of all data.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
SetYLabel($label)
Set y label.
SetMinValue($min)
Set min value.
draw($file, $fileurl= '')
Build a graph into memory using correct library (may also be wrote on disk, depending on library used...
dol_string_nospecial($str, $newstr= '_', $badcharstoreplace= '')
Clean a string from all punctuation characters to use it as a ref or login.
SetLabelInterval($x)
Set label interval to reduce number of labels.
SetLegendWidthMin($legendwidthmin)
Set min width.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
SetHorizTickIncrement($xi)
Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2.
SetNumXTicks($xt)
Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
setShowPointValue($showpointvalue)
Show pointvalue or not.
SetHideXGrid($bool)
Hide X grid.
SetDataColor($datacolor)
Set data.
draw_chart($file, $fileurl)
Build a graph using Chart library.
GetMinValue()
Get min value.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GetMaxValue()
Get max value.
SetTitle($title)
Set title.
print
Draft customers invoices.
SetBgColorGrid($bg_colorgrid=array(255, 255, 255))
Define background color of grid.
GetMinValueInData()
Return min value of all data.
SetShading($s)
Set shading.
SetHideYGrid($bool)
Hide Y grid.
GetCeilMaxValue()
Return max value of all data.
draw_jflot($file, $fileurl)
Build a graph using JFlot library.
ResetBgColor()
Reset bg color.
__construct($library= 'auto')
Constructor.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
GetMaxValueInData()
Get max value.
ResetDataColor()
Reset data color.
SetBgColor($bg_color=array(255, 255, 255))
Define background color of complete image.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...