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 $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++;
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')) {
1302 $this->stringtoshow .=
'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
1303 $this->stringtoshow .= $xaxis;
1315 $this->stringtoshow .=
'plugins: { '.
"\n";
1316 if (empty($showlegend)) {
1317 $this->stringtoshow .=
'legend: { display: false }, '.
"\n";
1319 $this->stringtoshow .=
'legend: { maxWidth: '.round(intVal($this->width) / 2).
', labels: { boxWidth: 15 }, position: \'' . (($showlegend && $showlegend == 2) ?
'right' :
'top') .
'\' },
'."\n";
1321 $this->stringtoshow .= "}, \n";
1323 /* For Chartjs v2.9 */
1325 $this->stringtoshow .= 'scales: { xAxis: [{
';
1326 if ($this->hideXValues) {
1327 $this->stringtoshow .= ' ticks: { display:
false }, display:
true,
';
1329 //$this->stringtoshow .= 'type: \
'time\', ';
1330 $this->stringtoshow .=
'distribution: \'linear\'';
1331 if ($type ==
'bar' && count($arrayofgroupslegend) > 0) {
1332 $this->stringtoshow .=
', stacked: true';
1334 $this->stringtoshow .=
' }]';
1335 $this->stringtoshow .=
', yAxis: [{ ticks: { beginAtZero: true }';
1336 if ($type ==
'bar' && count($arrayofgroupslegend) > 0) {
1337 $this->stringtoshow .=
', stacked: true';
1339 $this->stringtoshow .=
' }] }';
1343 if (is_array($this->tooltipsLabels) || is_array($this->tooltipsTitles)) {
1344 $this->stringtoshow .=
', tooltips: { mode: \'nearest\',
1346 if (is_array($this->tooltipsTitles)) {
1347 $this->stringtoshow .=
'
1348 title: function(tooltipItem, data) {
1349 var tooltipsTitle ='.json_encode($this->tooltipsTitles).
'
1350 return tooltipsTitle[tooltipItem[0].datasetIndex];
1353 if (is_array($this->tooltipsLabels)) {
1354 $this->stringtoshow .=
'label: function(tooltipItem, data) {
1355 var tooltipslabels ='.json_encode($this->tooltipsLabels).
'
1356 return tooltipslabels[tooltipItem.datasetIndex]
1359 $this->stringtoshow .=
'}},';
1361 $this->stringtoshow .=
'};';
1362 $this->stringtoshow .=
'
1363 var ctx = document.getElementById("canvas_' . $tag .
'").getContext("2d");
1364 var chart = new Chart(ctx, {
1365 // The type of chart we want to create
1366 type: \'' . $type .
'\',
1373 foreach ($legends as $val) { // Loop on each serie
1375 $this->stringtoshow .= ',
';
1377 $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'";
1381 //var_dump($arrayofgroupslegend);
1383 $this->stringtoshow .= '],
1386 global $theme_datacolor;
1387 //var_dump($arrayofgroupslegend);
1391 while ($i < $nblot) { // Loop on each serie
1392 $foundnegativecolor = 0;
1393 $usecolorvariantforgroupby = 0;
1394 // We used a 'group by
' and we have too many colors so we generated color variants per
1395 if (!empty($arrayofgroupslegend) && is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by.
1396 $nbofcolorneeds = count($arrayofgroupslegend);
1397 $nbofcolorsavailable = count($theme_datacolor);
1398 if ($nbofcolorneeds > $nbofcolorsavailable) {
1399 $usecolorvariantforgroupby = 1;
1402 $textoflegend = $arrayofgroupslegend[$i]['legendwithgroup
'];
1404 $textoflegend = !empty($this->Legend[$i]) ? $this->Legend[$i] : '';
1407 if ($usecolorvariantforgroupby) {
1408 $newcolor = $this->datacolor[$arrayofgroupslegend[$i]['stacknum
']];
1409 // If we change the stack
1410 if ($oldstacknum == -1 || $arrayofgroupslegend[$i]['stacknum
'] != $oldstacknum) {
1414 //var_dump($iinstack);
1416 // Change color with offset of $$iinstack
1417 //var_dump($newcolor);
1418 if ($iinstack % 2) { // We increase agressiveness of reference color for color 2, 4, 6, ...
1419 $ratio = min(95, 10 + 10 * $iinstack); // step of 20
1420 $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10
1421 } else { // We decrease agressiveness of reference color for color 3, 5, 7, ..
1422 $ratio = max(-100, -15 * $iinstack + 10); // step of -20
1423 $brightnessratio = min(90, 10 * $iinstack); // step of 20
1425 //var_dump('Color
'.($iinstack+1).' :
'.$ratio.' '.$brightnessratio);
1427 $newcolor = array_values(colorHexToRgb(colorAgressiveness(colorArrayToHex($newcolor), $ratio, $brightnessratio), false, true));
1429 $oldstacknum = $arrayofgroupslegend[$i]['stacknum
'];
1431 $color = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ', 0.9)
';
1432 $bordercolor = 'rgb(
' . $newcolor[0] . ',
' . $newcolor[1] . ',
' . $newcolor[2] . ')
';
1433 } else { // We do not use a 'group by
'
1434 if (!empty($this->datacolor[$i]) && is_array($this->datacolor[$i])) {
1435 $color = 'rgb(
' . $this->datacolor[$i][0] . ',
' . $this->datacolor[$i][1] . ',
' . $this->datacolor[$i][2] . ', 0.9)
';
1437 $color = $this->datacolor[$i];
1439 if (!empty($this->bordercolor[$i]) && is_array($this->bordercolor[$i])) {
1440 $bordercolor = 'rgb(
' . $this->bordercolor[$i][0] . ',
' . $this->bordercolor[$i][1] . ',
' . $this->bordercolor[$i][2] . ', 0.9)
';
1442 if ($type != 'horizontalBar
') {
1443 $bordercolor = $color;
1445 $bordercolor = $this->bordercolor[$i];
1449 // For negative colors, we invert border and background
1450 $tmp = str_replace('#
', '', $color);
1451 if (strpos($tmp, '-
') !== false) {
1452 $foundnegativecolor++;
1453 $bordercolor = str_replace('-
', '', $color);
1454 $color = '#FFFFFF
'; // If $val is '-123
'
1458 $this->stringtoshow .= ',
';
1460 $this->stringtoshow .= "\n";
1461 $this->stringtoshow .= '{
';
1462 $this->stringtoshow .= 'dolibarrinfo: \
'y_' . $i .
'\',
';
1464 $this->stringtoshow .= 'pointStyle: \
'' . ((!empty($this->
type[$i]) && $this->
type[$i] ==
'linesnopoint') ?
'line' :
'circle') .
'\',
';
1465 $this->stringtoshow .= 'fill:
' . ($type == 'bar
' ? 'true' : 'false') . ',
';
1466 if ($type == 'bar
' || $type == 'horizontalBar
') {
1467 $this->stringtoshow .= 'borderWidth: \
''.$this->borderwidth.
'\',
';
1469 $this->stringtoshow .= 'borderColor: \
'' . $bordercolor .
'\',
';
1470 $this->stringtoshow .= 'backgroundColor: \
'' . $color .
'\',
';
1471 if (!empty($arrayofgroupslegend) && !empty($arrayofgroupslegend[$i])) {
1472 $this->stringtoshow .= 'stack: \
'' . $arrayofgroupslegend[$i][
'stacknum'] .
'\',
';
1474 $this->stringtoshow .= 'data: [
';
1476 $this->stringtoshow .= $this->mirrorGraphValues ? '[
' . -$serie[$i] . ',
' . $serie[$i] . ']
' : $serie[$i];
1477 $this->stringtoshow .= ']
';
1478 $this->stringtoshow .= '}
' . "\n";
1483 $this->stringtoshow .= ']
' . "\n";
1484 $this->stringtoshow .= '}
' . "\n";
1485 $this->stringtoshow .= '});
' . "\n";
1488 $this->stringtoshow .= '</script>
' . "\n";
1497 public function total()
1500 foreach ($this->data as $valarray) { // Loop on each x
1501 $value += $valarray[1];
1512 public function show($shownographyet = 0)
1516 if ($shownographyet) {
1517 $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>
';
1518 $s .= '<div
class=
"nographyettext margintoponly">
';
1519 if (is_numeric($shownographyet)) {
1520 $s .= $langs->trans("NotEnoughDataYet") . '...
';
1522 $s .= $shownographyet . '...
';
1528 return $this->stringtoshow;
1539 public static function getDefaultGraphSizeForStats($direction, $defaultsize = '')
1543 if ($direction == 'width
') {
1544 if (empty($conf->dol_optimize_smallscreen)) {
1545 return ($defaultsize ? $defaultsize : '500
');
1547 return (empty($_SESSION['dol_screenwidth
']) ? '280
' : ($_SESSION['dol_screenwidth
'] - 40));
1550 if ($direction == 'height
') {
1551 return (empty($conf->dol_optimize_smallscreen) ? ($defaultsize ? $defaultsize : '220
') : '200
');