I'm facing an issue that I couldn't find anything here that helps me.
I'm using ChartNew.js which is possible to set legend of datas in Chart for end user. Even set this option in my JavaScript, this option seems nos working for me. Although my chart works properly with Ajax Request and shows the results in the screen, but only legend option seems not to cooperate.
Can anyone help me and find out why this legend not working?
My entire JavaScript code bellow:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "<?php echo "http://".$_SERVER['SERVER_NAME']."/epedidos/Dashboard/dataChart/";?>",
success: function(response) {
var obj = JSON.parse(response);
//console.log(obj.Cidade);
var valorMax = obj.reduce(function(a, b) {
return Math.max(a, b.Valor);
}, 0);
var scale = valorMax / 10;
//console.log(valorMax);
var cidade = new Array();
var valor = new Array();
var i = 0;
for ( i in obj) {
cidade[i] = obj[i].Cidade;
valor[i] = obj[i].Valor;
}
drawBarChart(cidade, valor, scale);
}
});
function drawBarChart(cidade, valor, scale){
var barChartData = {
labels : cidade,
datasets : [
{
label : "Vendas",
fillColor : "rgba(0,0,220,0.5)",
strokeColor : "rgba(0,0,220,0.8)",
highlightFill: "rgba(0,0,220,0.75)",
highlightStroke: "rgba(0,0,220,1)",
legend: "Vendas Mensais",
data : valor
}
]
}
var barOptions = {
responsive : true,
barValueSpacing : 12,
barDatasetSpacing : 5,
scaleFontSize: 12,
legend: true,
inGraphDataShow: true,
showTooltips: true,
yAxisUnit: "R$",
yAxisLabel: "Valores R$",
yAxisLeft : true,
xAxisLabel: "Top 10 Cidades",
xAxisTop: true,
scaleLabel : "R$ <%=value%>",
inGraphDataTmpl : "R$ <%=v3%>",
scaleOverride : true,
scaleStartValue : 0,
scaleSteps : 10,
scaleStepWidth : scale,
thousandSeparator : ".",
decimalSeparator : ",",
roundNumber : 0
}
var ctx = document.getElementById("bar-chart").getContext("2d");
window.myBar = new Chart(ctx).Bar(barChartData, barOptions);
}
});