42 public $type = array();
43 public $mode =
'side';
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 $hideXValues =
false;
70 public $hideYGrid =
false;
72 public $Legend = array();
73 public $LegendWidthMin = 0;
74 public $showlegend = 1;
75 public $showpointvalue = 1;
76 public $showpercent = 0;
82 public $mirrorGraphValues =
false;
83 public $tooltipsTitles =
null;
84 public $tooltipsLabels =
null;
93 public $bgcolorgrid = array(255, 255, 255);
95 public $borderwidth = 1;
97 private $stringtoshow;
108 global $theme_bordercolor, $theme_datacolor, $theme_bgcolor;
111 $this->bordercolor = array(235, 235, 224);
112 $this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220));
113 $this->bgcolor = array(235, 235, 224);
116 $color_file = DOL_DOCUMENT_ROOT .
'/theme/' . $conf->theme .
'/theme_vars.inc.php';
117 if (is_readable($color_file)) {
119 if (isset($theme_bordercolor)) {
120 $this->bordercolor = $theme_bordercolor;
122 if (isset($theme_datacolor)) {
123 $this->datacolor = $theme_datacolor;
125 if (isset($theme_bgcolor)) {
126 $this->bgcolor = $theme_bgcolor;
131 $this->_library = $library;
132 if ($this->_library ==
'auto') {
133 $this->_library = (empty($conf->global->MAIN_JS_GRAPH) ?
'chart' : $conf->global->MAIN_JS_GRAPH);
148 $this->horizTickIncrement = $xi;
176 $this->labelInterval = $x;
190 $this->hideXGrid = $bool;
202 $this->hideXValues = $bool;
216 $this->hideYGrid = $bool;
230 $this->YLabel = $label;
256 $this->title = $title;
283 $this->datacolor = $datacolor;
294 $this->bordercolor = $bordercolor;
305 $this->borderwidth = $borderwidth;
316 $this->tooltipsLabels = $tooltipsLabels;
327 $this->tooltipsTitles = $tooltipsTitles;
354 $this->Legend = $legend;
367 $this->LegendWidthMin = $legendwidthmin;
380 $this->MaxValue = $max;
392 return $this->MaxValue;
405 $this->MinValue = $min;
417 return $this->MinValue;
456 $this->cssprefix = $s;
468 unset($this->bgcolor);
480 unset($this->bgcolorgrid);
491 $this->mirrorGraphValues = $mirrorGraphValues;
512 $this->showlegend = $showlegend;
523 $this->showpointvalue = $showpointvalue;
534 $this->showpercent = $showpercent;
549 global $theme_bgcolor, $theme_bgcoloronglet;
551 if (!is_array($bg_color)) {
552 if ($bg_color ==
'onglet') {
554 $this->bgcolor = $theme_bgcoloronglet;
556 $this->bgcolor = $theme_bgcolor;
559 $this->bgcolor = $bg_color;
573 global $theme_bgcolor, $theme_bgcoloronglet;
575 if (!is_array($bg_colorgrid)) {
576 if ($bg_colorgrid ==
'onglet') {
578 $this->bgcolorgrid = $theme_bgcoloronglet;
580 $this->bgcolorgrid = $theme_bgcolor;
583 $this->bgcolorgrid = $bg_colorgrid;
596 unset($this->datacolor);
608 if (!is_array($this->data)) {
614 $nbseries = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
616 foreach ($this->data as $x) {
617 for ($i = 0; $i < $nbseries; $i++) {
620 } elseif ($max < $x[$i + 1]) {
638 if (!is_array($this->data)) {
644 $nbseries = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
646 foreach ($this->data as $x) {
647 for ($i = 0; $i < $nbseries; $i++) {
650 } elseif ($min > $x[$i + 1]) {
674 for ($i = 0; $i < ($size - 1); $i++) {
679 if (is_numeric($max)) {
680 $res = ceil($max / $factor) * $factor;
705 for ($i = 0; $i < ($size - 1); $i++) {
709 $res = floor($min / $factor) * $factor;
722 public function draw($file, $fileurl =
'')
725 $this->error =
"Call to draw method was made with empty value for parameter file.";
726 dol_syslog(get_class($this) .
"::draw " . $this->error, LOG_ERR);
729 if (!is_array($this->data)) {
730 $this->error =
"Call to draw method was made but SetData was not called or called with an empty dataset for parameters";
731 dol_syslog(get_class($this) .
"::draw " . $this->error, LOG_ERR);
734 if (count($this->data) < 1) {
735 $this->error =
"Call to draw method was made but SetData was is an empty dataset";
736 dol_syslog(get_class($this) .
"::draw " . $this->error, LOG_WARNING);
738 $call =
"draw_" . $this->_library;
739 call_user_func_array(array($this, $call), array($file, $fileurl));
762 global $conf, $langs;
764 dol_syslog(get_class($this) .
"::draw_jflot this->type=" . join(
',', $this->
type) .
" this->MaxValue=" . $this->MaxValue);
766 if (empty($this->width) && empty($this->height)) {
767 print
'Error width or height not set';
773 if (is_array($this->data) && is_array($this->data[0])) {
774 $nblot = count($this->data[0]) - 1;
777 dol_syslog(
'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
785 while ($i < $nblot) {
787 $serie[$i] =
"var d" . $i .
" = [];\n";
791 foreach ($this->data as $valarray) {
792 $legends[$x] = $valarray[0];
793 $values[$x] = (is_numeric($valarray[$i + 1]) ? $valarray[$i + 1] :
null);
797 if (isset($this->
type[$firstlot]) && in_array($this->
type[$firstlot], array(
'pie',
'piesemicircle',
'polar'))) {
798 foreach ($values as $x => $y) {
800 $serie[$i] .=
'd' . $i .
'.push({"label":"' .
dol_escape_js($legends[$x]) .
'", "data":' . $y .
'});' .
"\n";
804 foreach ($values as $x => $y) {
806 $serie[$i] .=
'd' . $i .
'.push([' . $x .
', ' . $y .
']);' .
"\n";
816 $this->stringtoshow =
'<!-- Build using jflot -->' .
"\n";
817 if (!empty($this->title)) {
818 $this->stringtoshow .=
'<div class="center dolgraphtitle' . (empty($this->cssprefix) ?
'' :
' dolgraphtitle' . $this->cssprefix) .
'">' . $this->title .
'</div>';
820 if (!empty($this->shownographyet)) {
821 $this->stringtoshow .=
'<div style="width:' . $this->width .
'px;height:' . $this->height .
'px;" class="nographyet"></div>';
822 $this->stringtoshow .=
'<div class="nographyettext margintoponly">' . $langs->trans(
"NotEnoughDataYet") .
'...</div>';
827 $dolxaxisvertical =
'';
828 if (count($this->data) > 20) {
829 $dolxaxisvertical =
'dol-xaxis-vertical';
831 $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";
833 $this->stringtoshow .=
'<script id="' . $tag .
'">' .
"\n";
834 $this->stringtoshow .=
'$(function () {' .
"\n";
837 $this->stringtoshow .=
'<!-- No series of data -->' .
"\n";
839 while ($i < $nblot) {
840 $this->stringtoshow .=
'<!-- Serie ' . $i .
' -->' .
"\n";
841 $this->stringtoshow .= $serie[$i] .
"\n";
845 $this->stringtoshow .=
"\n";
848 if (isset($this->
type[$firstlot]) && in_array($this->
type[$firstlot], array(
'pie',
'piesemicircle',
'polar'))) {
849 $datacolor = array();
850 foreach ($this->datacolor as $val) {
851 if (is_array($val)) {
852 $datacolor[] =
"#" . sprintf(
"%02x%02x%02x", $val[0], $val[1], $val[2]);
854 $datacolor[] =
"#" . str_replace(array(
'#',
'-'),
'', $val);
859 $showlegend = $this->showlegend;
860 $showpointvalue = $this->showpointvalue;
861 $showpercent = $this->showpercent;
863 $this->stringtoshow .=
'
864 function plotWithOptions_' . $tag .
'() {
865 $.plot($("#placeholder_' . $tag .
'"), d0,
871 ' . ($this->combine ?
'
873 threshold: ' . $this->combine .
'
878 formatter: function(label, series) {
879 var percent=Math.round(series.percent);
880 var number=series.data[0][1];
882 $this->stringtoshow .=
'<span style="font-size:8pt;text-align:center;padding:2px;color:black;">';
884 $this->stringtoshow .=
'<a style="color: #FFFFFF;" border="0" href="' . $urltemp .
'">';
886 $this->stringtoshow .=
'\'+
';
887 $this->stringtoshow .= ($showlegend ? '' : 'label+\
' \'+');
888 $this->stringtoshow .= ($showpointvalue ?
'number+' :
'');
889 $this->stringtoshow .= ($showpercent ?
'\'<br>\
'+percent+\'%\'+' :
'');
890 $this->stringtoshow .=
'\'';
892 $this->stringtoshow .=
'</a>';
894 $this->stringtoshow .=
'</span>\';
909 if (count($datacolor)) {
910 $this->stringtoshow .=
'colors: ' . (!empty(
$data[
'seriescolor']) ? json_encode(
$data[
'seriescolor']) : json_encode($datacolor)) .
',';
912 $this->stringtoshow .=
'legend: {show: ' . ($showlegend ?
'true' :
'false') .
', position: \'ne\' }
919 $this->stringtoshow .=
'
920 function showTooltip_' . $tag .
'(x, y, contents) {
921 $(\'<div class="graph-tooltip-inner" id="tooltip_' . $tag .
'">\' + contents + \'</div>\').css({
922 position: \'absolute\',
926 border: \'1px solid #000\',
928 \'background-color\': \'#000\',
930 \'font-weight\': \'bold\',
933 }).appendTo("body").fadeIn(100);
936 var previousPoint = null;
937 $("#placeholder_' . $tag .
'").bind("plothover", function (event, pos, item) {
938 $("#x").text(pos.x.toFixed(2));
939 $("#y").text(pos.y.toFixed(2));
942 if (previousPoint != item.dataIndex) {
943 previousPoint = item.dataIndex;
945 $("#tooltip").remove();
946 /* console.log(item); */
947 var x = item.datapoint[0].toFixed(2);
948 var y = item.datapoint[1].toFixed(2);
949 var z = item.series.xaxis.ticks[item.dataIndex].label;
951 if ($this->showpointvalue > 0) {
952 $this->stringtoshow .=
'
953 showTooltip_' . $tag .
'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
956 $this->stringtoshow .=
'
960 $("#tooltip_' . $tag .
'").remove();
961 previousPoint = null;
966 $this->stringtoshow .=
'var stack = null, steps = false;' .
"\n";
968 $this->stringtoshow .=
'function plotWithOptions_' . $tag .
'() {' .
"\n";
969 $this->stringtoshow .=
'$.plot($("#placeholder_' . $tag .
'"), [ ' .
"\n";
971 while ($i < $nblot) {
972 if ($i > $firstlot) {
973 $this->stringtoshow .=
', ' .
"\n";
975 $color = sprintf(
"%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
976 $this->stringtoshow .=
'{ ';
977 if (!isset($this->
type[$i]) || $this->
type[$i] ==
'bars') {
979 if ($i == $firstlot) {
981 } elseif ($i == $firstlot + 1) {
986 $this->stringtoshow .=
'bars: { lineWidth: 1, show: true, align: "' . $align .
'", barWidth: 0.45 }, ';
988 $this->stringtoshow .=
'bars: { lineWidth: 1, show: true, align: "' . ($i == $firstlot ?
'center' :
'left') .
'", barWidth: 0.5 }, ';
991 if (isset($this->
type[$i]) && ($this->
type[$i] ==
'lines' || $this->
type[$i] ==
'linesnopoint')) {
992 $this->stringtoshow .=
'lines: { show: true, fill: false }, points: { show: ' . ($this->
type[$i] ==
'linesnopoint' ?
'false' :
'true') .
' }, ';
994 $this->stringtoshow .=
'color: "#' . $color .
'", label: "' . (isset($this->Legend[$i]) ?
dol_escape_js($this->Legend[$i]) :
'') .
'", data: d' . $i .
' }';
998 $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";
1001 $this->stringtoshow .=
', xaxis: { ticks: [' .
"\n";
1003 foreach ($this->data as $key => $valarray) {
1005 $this->stringtoshow .=
', ' .
"\n";
1007 $this->stringtoshow .=
' [' . $x .
', "' . $valarray[0] .
'"]';
1010 $this->stringtoshow .=
'] }' .
"\n";
1013 $this->stringtoshow .=
', yaxis: { min: ' . $this->MinValue .
', max: ' . ($this->MaxValue) .
' }' .
"\n";
1016 $color1 = sprintf(
"%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]);
1017 $color2 = sprintf(
"%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
1018 $this->stringtoshow .=
', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 .
'", "#' . $color2 .
'"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }' .
"\n";
1019 $this->stringtoshow .=
'});' .
"\n";
1020 $this->stringtoshow .=
'}' .
"\n";
1023 $this->stringtoshow .=
'plotWithOptions_' . $tag .
'();' .
"\n";
1024 $this->stringtoshow .=
'});' .
"\n";
1025 $this->stringtoshow .=
'</script>' .
"\n";
1049 global $conf, $langs;
1051 dol_syslog(get_class($this) .
"::draw_chart this->type=" . join(
',', $this->
type) .
" this->MaxValue=" . $this->MaxValue);
1053 if (empty($this->width) && empty($this->height)) {
1054 print
'Error width or height not set';
1058 $showlegend = $this->showlegend;
1063 if (is_array($this->data)) {
1064 foreach ($this->data as $valarray) {
1065 $nblot = max($nblot, count($valarray) - 1);
1070 dol_syslog(
'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
1077 $arrayofgroupslegend = array();
1081 while ($i < $nblot) {
1087 foreach ($this->data as $valarray) {
1088 $legends[$x] = (array_key_exists(
'label', $valarray) ? $valarray[
'label'] : $valarray[0]);
1089 $array_of_ykeys = array_keys($valarray);
1091 $tmpykey = explode(
'_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3);
1092 if (isset($tmpykey[2]) && (!empty($tmpykey[2]) || $tmpykey[2] ==
'0')) {
1093 $tmpvalue = (array_key_exists(
'y_' . $tmpykey[1] .
'_' . $tmpykey[2], $valarray) ? $valarray[
'y_' . $tmpykey[1] .
'_' . $tmpykey[2]] : $valarray[$i + 1]);
1094 $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue :
null);
1095 $arrayofgroupslegend[$i] = array(
1096 'stacknum' => $tmpykey[1],
1097 'legend' => $this->Legend[$tmpykey[1]],
1098 'legendwithgroup' => $this->Legend[$tmpykey[1]] .
' - ' . $tmpykey[2]
1101 $tmpvalue = (array_key_exists(
'y_' . $i, $valarray) ? $valarray[
'y_' . $i] : $valarray[$i + 1]);
1103 $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue :
null);
1109 foreach ($values as $x => $y) {
1111 $serie[$i] .= ($j > 0 ?
", " :
"") . $y;
1113 $serie[$i] .= ($j > 0 ?
", " :
"") .
'null';
1126 $this->stringtoshow =
'<!-- Build using chart -->' .
"\n";
1127 if (!empty($this->title)) {
1128 $this->stringtoshow .=
'<div class="center dolgraphtitle' . (empty($this->cssprefix) ?
'' :
' dolgraphtitle' . $this->cssprefix) .
'">' . $this->title .
'</div>';
1130 if (!empty($this->shownographyet)) {
1131 $this->stringtoshow .=
'<div style="width:' . $this->width . (strpos($this->width,
'%') > 0 ?
'' :
'px') .
'; height:' . $this->height .
'px;" class="nographyet"></div>';
1132 $this->stringtoshow .=
'<div class="nographyettext margintoponly">' . $langs->trans(
"NotEnoughDataYet") .
'...</div>';
1137 $dolxaxisvertical =
'';
1138 if (count($this->data) > 20) {
1139 $dolxaxisvertical =
'dol-xaxis-vertical';
1142 $cssfordiv =
'dolgraphchart';
1143 if (isset($this->
type[$firstlot])) {
1144 $cssfordiv .=
' dolgraphchar' . $this->
type[$firstlot];
1146 $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";
1148 $this->stringtoshow .=
'<script id="' . $tag .
'">' .
"\n";
1151 $this->stringtoshow .=
'<!-- No series of data -->';
1153 while ($i < $nblot) {
1159 $this->stringtoshow .=
"\n";
1162 if (isset($this->
type[$firstlot]) && (in_array($this->
type[$firstlot], array(
'pie',
'polar',
'piesemicircle')))) {
1163 $type = $this->
type[$firstlot];
1165 $this->stringtoshow .=
'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
1168 $legendMaxLines = 0;
1171 if (empty($showlegend)) {
1172 $this->stringtoshow .=
'legend: { display: false }, ';
1174 $this->stringtoshow .=
'legend: { labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ?
'right' :
'top') .
'\'';
1175 if (!empty($legendMaxLines)) {
1176 $this->stringtoshow .=
', maxLines: ' . $legendMaxLines;
1178 $this->stringtoshow .=
' }, ' .
"\n";
1182 $this->stringtoshow .=
'plugins: { ';
1183 if (empty($showlegend)) {
1184 $this->stringtoshow .=
'legend: { display: false }, ';
1186 $this->stringtoshow .=
'legend: { labels: { boxWidth: 15 }, position: \'' . ($showlegend == 2 ?
'right' :
'top') .
'\'';
1187 if (!empty($legendMaxLines)) {
1188 $this->stringtoshow .=
', maxLines: ' . $legendMaxLines;
1190 $this->stringtoshow .=
' }, ' .
"\n";
1192 $this->stringtoshow .=
' }, ' .
"\n";
1195 if ($this->
type[$firstlot] ==
'piesemicircle') {
1196 $this->stringtoshow .=
'circumference: Math.PI,' .
"\n";
1197 $this->stringtoshow .=
'rotation: -Math.PI,' .
"\n";
1199 $this->stringtoshow .=
'elements: { arc: {' .
"\n";
1201 $this->stringtoshow .=
'backgroundColor: [';
1203 $foundnegativecolor = 0;
1204 foreach ($legends as $val) {
1206 $this->stringtoshow .=
', ' .
"\n";
1208 if (is_array($this->datacolor[$i])) {
1209 $color =
'rgb(' . $this->datacolor[$i][0] .
', ' . $this->datacolor[$i][1] .
', ' . $this->datacolor[$i][2] .
')';
1211 $tmp = str_replace(
'#',
'', $this->datacolor[$i]);
1212 if (strpos($tmp,
'-') !==
false) {
1213 $foundnegativecolor++;
1214 $color =
'rgba(0,0,0,.0)';
1216 $color =
"#" . $tmp;
1219 $this->stringtoshow .=
"'" . $color .
"'";
1222 $this->stringtoshow .=
'], ' .
"\n";
1224 if ($foundnegativecolor) {
1225 $this->stringtoshow .=
'borderColor: [';
1227 foreach ($legends as $val) {
1229 $this->stringtoshow .=
', ' .
"\n";
1231 if (is_array($this->datacolor[$i])) {
1234 $tmp = str_replace(
'#',
'', $this->datacolor[$i]);
1235 if (strpos($tmp,
'-') !==
false) {
1236 $color =
'#' . str_replace(
'-',
'', $tmp);
1241 $this->stringtoshow .= ($color ==
'null' ?
"'rgba(0,0,0,0.2)'" :
"'" . $color .
"'");
1244 $this->stringtoshow .=
']';
1246 $this->stringtoshow .=
'} } };' .
"\n";
1248 $this->stringtoshow .=
'
1249 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1250 var chart = new Chart(ctx, {
1251 // The type of chart we want to create
1252 type: \'' . (in_array($type, array(
'pie',
'piesemicircle')) ?
'doughnut' :
'polarArea') .
'\',
1259 foreach ($legends as $val) { // Loop on each serie
1261 $this->stringtoshow .= ',
';
1263 $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 25)) . "'"; // Lower than 25 make some important label (that we can't shorten) to be truncated
1267 $this->stringtoshow .=
'],
1271 while ($i < $nblot) {
1272 $color =
'rgb(' . $this->datacolor[$i][0] .
', ' . $this->datacolor[$i][1] .
', ' . $this->datacolor[$i][2] .
')';
1276 $this->stringtoshow .=
', ' .
"\n";
1278 $this->stringtoshow .=
'{' .
"\n";
1281 $this->stringtoshow .=
' data: [' . $serie[$i] .
']';
1282 $this->stringtoshow .=
'}' .
"\n";
1285 $this->stringtoshow .=
']' .
"\n";
1286 $this->stringtoshow .=
'}' .
"\n";
1287 $this->stringtoshow .=
'});' .
"\n";
1290 $type =
'bar'; $xaxis =
'';
1292 if (!isset($this->
type[$firstlot]) || $this->
type[$firstlot] ==
'bars') {
1295 if (isset($this->
type[$firstlot]) && $this->
type[$firstlot] ==
'horizontalbars') {
1296 $type =
'bar'; $xaxis =
"indexAxis: 'y', ";
1298 if (isset($this->
type[$firstlot]) && ($this->
type[$firstlot] ==
'lines' || $this->
type[$firstlot] ==
'linesnopoint')) {
1303 $this->stringtoshow .=
'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
1304 $this->stringtoshow .= $xaxis;
1305 if ($this->showpointvalue == 2) {
1306 $this->stringtoshow .=
'interaction: { intersect: true, mode: \'index\'}, ';
1319 $this->stringtoshow .=
'plugins: { '.
"\n";
1320 if (empty($showlegend)) {
1321 $this->stringtoshow .=
'legend: { display: false }, '.
"\n";
1323 $this->stringtoshow .=
'legend: { maxWidth: '.round(intVal($this->width) / 2).
', labels: { boxWidth: 15 }, position: \'' . (($showlegend && $showlegend == 2) ?
'right' :
'top') .
'\' },
'."\n";
1325 $this->stringtoshow .= "}, \n";
1327 /* For Chartjs v2.9 */
1329 $this->stringtoshow .= 'scales: { xAxis: [{
';
1330 if ($this->hideXValues) {
1331 $this->stringtoshow .= ' ticks: { display:
false }, display:
true,
';
1333 //$this->stringtoshow .= 'type: \
'time\', ';
1334 $this->stringtoshow .=
'distribution: \'linear\'';
1335 if ($type ==
'bar' && count($arrayofgroupslegend) > 0) {
1336 $this->stringtoshow .=
', stacked: true';
1338 $this->stringtoshow .=
' }]';
1339 $this->stringtoshow .=
', yAxis: [{ ticks: { beginAtZero: true }';
1340 if ($type ==
'bar' && count($arrayofgroupslegend) > 0) {
1341 $this->stringtoshow .=
', stacked: true';
1343 $this->stringtoshow .=
' }] }';
1347 if (is_array($this->tooltipsLabels) || is_array($this->tooltipsTitles)) {
1348 $this->stringtoshow .=
', tooltips: { mode: \'nearest\',
1350 if (is_array($this->tooltipsTitles)) {
1351 $this->stringtoshow .=
'
1352 title: function(tooltipItem, data) {
1353 var tooltipsTitle ='.json_encode($this->tooltipsTitles).
'
1354 return tooltipsTitle[tooltipItem[0].datasetIndex];
1357 if (is_array($this->tooltipsLabels)) {
1358 $this->stringtoshow .=
'label: function(tooltipItem, data) {
1359 var tooltipslabels ='.json_encode($this->tooltipsLabels).
'
1360 return tooltipslabels[tooltipItem.datasetIndex]
1363 $this->stringtoshow .=
'}},';
1365 $this->stringtoshow .=
'};';
1366 $this->stringtoshow .=
'
1367 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1368 var chart = new Chart(ctx, {
1369 // The type of chart we want to create
1370 type: \'' . $type .
'\',
1377 foreach ($legends as $val) { // Loop on each serie
1379 $this->stringtoshow .= ',
';
1381 $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'";
1385 //var_dump($arrayofgroupslegend);
1387 $this->stringtoshow .= '],
1390 global $theme_datacolor;
1391 //var_dump($arrayofgroupslegend);
1395 while ($i < $nblot) { // Loop on each serie
1396 $foundnegativecolor = 0;
1397 $usecolorvariantforgroupby = 0;
1398 // We used a 'group by
' and we have too many colors so we generated color variants per
1399 if (!empty($arrayofgroupslegend) && is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by.
1400 $nbofcolorneeds = count($arrayofgroupslegend);
1401 $nbofcolorsavailable = count($theme_datacolor);
1402 if ($nbofcolorneeds > $nbofcolorsavailable) {
1403 $usecolorvariantforgroupby = 1;
1406 $textoflegend = $arrayofgroupslegend[$i]['legendwithgroup
'];
1408 $textoflegend = !empty($this->Legend[$i]) ? $this->Legend[$i] : '';
1411 if ($usecolorvariantforgroupby) {
1412 $newcolor = $this->datacolor[$arrayofgroupslegend[$i]['stacknum
']];
1413 // If we change the stack
1414 if ($oldstacknum == -1 || $arrayofgroupslegend[$i]['stacknum
'] != $oldstacknum) {
1418 //var_dump($iinstack);
1420 // Change color with offset of $$iinstack
1421 //var_dump($newcolor);
1422 if ($iinstack % 2) { // We increase agressiveness of reference color for color 2, 4, 6, ...
1423 $ratio = min(95, 10 + 10 * $iinstack); // step of 20
1424 $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10
1425 } else { // We decrease agressiveness of reference color for color 3, 5, 7, ..
1426 $ratio = max(-100, -15 * $iinstack + 10); // step of -20
1427 $brightnessratio = min(90, 10 * $iinstack); // step of 20
1429 //var_dump('Color
'.($iinstack+1).' :
'.$ratio.' '.$brightnessratio);
1431 $newcolor = array_values(colorHexToRgb(colorAgressiveness(colorArrayToHex($newcolor), $ratio, $brightnessratio), false, true));
1433 $oldstacknum = $arrayofgroupslegend[$i]['stacknum
'];
1435 $color = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ', 0.9)
';
1436 $bordercolor = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ')
';
1437 } else { // We do not use a 'group by
'
1438 if (!empty($this->datacolor[$i]) && is_array($this->datacolor[$i])) {
1439 $color = 'rgb(
' . $this->datacolor[$i][0] . ',
' . $this->datacolor[$i][1] . ',
' . $this->datacolor[$i][2] . ', 0.9)
';
1441 $color = $this->datacolor[$i];
1443 if (!empty($this->bordercolor[$i]) && is_array($this->bordercolor[$i])) {
1444 $bordercolor = 'rgb(
' . $this->bordercolor[$i][0] . ',
' . $this->bordercolor[$i][1] . ',
' . $this->bordercolor[$i][2] . ', 0.9)
';
1446 if ($type != 'horizontalBar
') {
1447 $bordercolor = $color;
1449 $bordercolor = $this->bordercolor[$i];
1453 // For negative colors, we invert border and background
1454 $tmp = str_replace('#
', '', $color);
1455 if (strpos($tmp, '-
') !== false) {
1456 $foundnegativecolor++;
1457 $bordercolor = str_replace('-
', '', $color);
1458 $color = '#FFFFFF
'; // If $val is '-123
'
1462 $this->stringtoshow .= ',
';
1464 $this->stringtoshow .= "\n";
1465 $this->stringtoshow .= '{
';
1466 $this->stringtoshow .= 'dolibarrinfo: \
'y_' . $i .
'\',
';
1468 $this->stringtoshow .= 'pointStyle: \
'' . ((!empty($this->
type[$i]) && $this->
type[$i] ==
'linesnopoint') ?
'line' :
'circle') .
'\',
';
1469 $this->stringtoshow .= 'fill:
' . ($type == 'bar
' ? 'true' : 'false') . ',
';
1470 if ($type == 'bar
' || $type == 'horizontalBar
') {
1471 $this->stringtoshow .= 'borderWidth: \
''.$this->borderwidth.
'\',
';
1473 $this->stringtoshow .= 'borderColor: \
'' . $bordercolor .
'\',
';
1474 $this->stringtoshow .= 'backgroundColor: \
'' . $color .
'\',
';
1475 if (!empty($arrayofgroupslegend) && !empty($arrayofgroupslegend[$i])) {
1476 $this->stringtoshow .= 'stack: \
'' . $arrayofgroupslegend[$i][
'stacknum'] .
'\',
';
1478 $this->stringtoshow .= 'data: [
';
1480 $this->stringtoshow .= $this->mirrorGraphValues ? '[
' . -$serie[$i] . ',
' . $serie[$i] . ']
' : $serie[$i];
1481 $this->stringtoshow .= ']
';
1482 $this->stringtoshow .= '}
' . "\n";
1487 $this->stringtoshow .= ']
' . "\n";
1488 $this->stringtoshow .= '}
' . "\n";
1489 $this->stringtoshow .= '});
' . "\n";
1492 $this->stringtoshow .= '</script>
' . "\n";
1501 public function total()
1504 foreach ($this->data as $valarray) { // Loop on each x
1505 $value += $valarray[1];
1516 public function show($shownographyet = 0)
1520 if ($shownographyet) {
1521 $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>
';
1522 $s .= '<div
class=
"nographyettext margintoponly">
';
1523 if (is_numeric($shownographyet)) {
1524 $s .= $langs->trans("NotEnoughDataYet") . '...
';
1526 $s .= $shownographyet . '...
';
1532 return $this->stringtoshow;
1543 public static function getDefaultGraphSizeForStats($direction, $defaultsize = '')
1547 if ($direction == 'width
') {
1548 if (empty($conf->dol_optimize_smallscreen)) {
1549 return ($defaultsize ? $defaultsize : '500
');
1551 return (empty($_SESSION['dol_screenwidth
']) ? '280
' : ($_SESSION['dol_screenwidth
'] - 40));
1554 if ($direction == 'height
') {
1555 return (empty($conf->dol_optimize_smallscreen) ? ($defaultsize ? $defaultsize : '220
') : '200
');
setTooltipsTitles($tooltipsTitles)
Set tooltips titles of the graph.
setTooltipsLabels($tooltipsLabels)
Set tooltips labels of the graph.
__construct($library='auto')
Constructor.
draw_jflot($file, $fileurl)
Build a graph using JFlot library.
draw($file, $fileurl='')
Build a graph into memory using correct library (may also be wrote on disk, depending on library used...
SetYLabel($label)
Set y label.
ResetDataColor()
Reset data color.
SetBgColorGrid($bg_colorgrid=array(255, 255, 255))
Define background color of grid.
SetHideYGrid($bool)
Hide Y grid.
SetHorizTickIncrement($xi)
Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2.
SetMinValue($min)
Set min value.
ResetBgColor()
Reset bg color.
setHideXValues($bool)
Hide X Values.
SetNumXTicks($xt)
Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2.
SetCssPrefix($s)
Set shading.
GetMaxValue()
Get max value.
GetCeilMaxValue()
Return max value of all data.
GetMaxValueInData()
Get max value among all values of all series.
GetMinValue()
Get min value.
SetHideXGrid($bool)
Hide X grid.
setMirrorGraphValues($mirrorGraphValues)
Mirror Values of the graph.
SetLabelInterval($x)
Set label interval to reduce number of labels.
SetDataColor($datacolor)
Set data color.
GetMinValueInData()
Return min value of all values of all series.
SetMaxValue($max)
Set max value.
SetLegend($legend)
Set legend.
setShowPercent($showpercent)
Show percent or not.
draw_chart($file, $fileurl)
Build a graph using Chart library.
setShowLegend($showlegend)
Show legend or not.
setBorderColor($bordercolor)
Set border color.
setBorderWidth($borderwidth)
Set border width.
SetTitle($title)
Set title.
SetLegendWidthMin($legendwidthmin)
Set min width.
ResetBgColorGrid()
Reset bgcolorgrid.
GetFloorMinValue()
Return min value of all data.
SetBgColor($bg_color=array(255, 255, 255))
Define background color of complete image.
SetShading($s)
Set shading.
setShowPointValue($showpointvalue)
Show pointvalue or not.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
Clean a string from all punctuation characters to use it as a ref or login.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type