Skip to content

Commit

Permalink
fix(Charts) set maximum scale value
Browse files Browse the repository at this point in the history
  • Loading branch information
joebordes committed Jul 15, 2017
1 parent 1895711 commit 8a84de8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Smarty/templates/Home/HomeBlock.tpl
Expand Up @@ -159,6 +159,12 @@ window.doChart{$HOME_STUFFID} = function(charttype) {ldelim}
backgroundColor: [{/literal}{foreach item=CVALUE name=chartvalues from=$HOME_STUFF.yaxisData}getRandomColor(){if not $smarty.foreach.chartvalues.last},{/if}{/foreach}{literal}]
}]
};
Chart.scaleService.updateScaleDefaults('linear', {
ticks: {
min: 0,
max: Math.max.apply(Math, chartDataObject.datasets[0].data)+1
}
});
window.schart{/literal}{$HOME_STUFFID}{literal} = new Chart(stuffchart,{
type: charttype,
data: chartDataObject,
Expand Down
7 changes: 5 additions & 2 deletions include/utils/ChartUtils.php
Expand Up @@ -165,7 +165,9 @@ public static function generateChartDataFromReports($queryResult, $groupbyField,
static public function getChartHTML($labels, $values, $graph_title, $target_values, $html_imagename, $width, $height, $left, $right, $top, $bottom, $graph_type, $legend_position='right', $responsive=true) {
$lbls = implode(',',$labels);
$vals = str_replace('::',',',$values);
$minscale = max(0,min(explode(',',$vals))-2);
$realvals = explode(',',$vals);
$minscale = max(0,min($realvals)-2);
$maxscale = max($realvals)+1;
$lnks = array();
$cnt=0;
foreach ($target_values as $value) {
Expand Down Expand Up @@ -211,7 +213,8 @@ static public function getChartHTML($labels, $values, $graph_title, $target_valu
};
Chart.scaleService.updateScaleDefaults('linear', {
ticks: {
min: $minscale
min: $minscale,
max: $maxscale
}
});
window.schart{$html_imagename} = new Chart(stuffchart,{
Expand Down

0 comments on commit 8a84de8

Please sign in to comment.