Skip to content

Commit

Permalink
Fixed issue #16562: Bar charts at statistics start with min value=1 b…
Browse files Browse the repository at this point in the history
…ut has to be min value=0 (#1575)

Setting options to explicitly start on 0
  • Loading branch information
gabrieljenik committed Oct 13, 2020
1 parent 5e66549 commit 494a622
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions assets/scripts/admin/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,25 @@ function init_chart_js_graph_with_datasets($type, $qid) {
dataDefinition.datasets[0].pointHoverBorderColor.push("rgba(" + COLORS_FOR_SURVEY[colorIndex] + ",1)");
});

var parsedType = parseType($type);
var options = {};

if (parsedType == 'bar' || parsedType == 'line') {
options.scales = {
yAxes: [{
ticks: {
suggestedMin: 0,
}
}]
};
}

console.ls.log("Creating chart with definition: ", dataDefinition);

window.chartjs[$qid] = new Chart($canvas, {
type: parseType($type),
data: dataDefinition
type: parsedType,
data: dataDefinition,
options: options,
});
}

Expand Down Expand Up @@ -180,10 +194,21 @@ function init_chart_js_graph_with_datas($type, $qid) {
$chartDef.datasets[0].hoverBackgroundColor.push("rgba(" + COLORS_FOR_SURVEY[colorIndex] + ",0.9)");
});

var parsedType = parseType($type);
var $options = {
tooltipTemplate: "<%if (label){%><%=label %>: <%}%><%= value + '%' %>",
};

if (parsedType == 'bar' || parsedType == 'line') {
options.scales = {
yAxes: [{
ticks: {
suggestedMin: 0,
}
}]
};
}

if (typeof chartjs != "undefined") {
if (typeof chartjs[$qid] != "undefined") {
window.chartjs[$qid].destroy();
Expand All @@ -193,7 +218,7 @@ function init_chart_js_graph_with_datas($type, $qid) {
console.ls.log("Creating chart with definition: ", $chartDef);

window.chartjs[$qid] = new Chart($canvas, {
type: parseType($type),
type: parsedType,
data: $chartDef,
options: $options
});
Expand Down

0 comments on commit 494a622

Please sign in to comment.