0

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);



    }       

});
cssyphus
  • 37,875
  • 18
  • 96
  • 111
bcesars
  • 1,016
  • 1
  • 17
  • 36
  • This: `<%=value%>`, should be ``...same for the other case... – Hackerman Dec 05 '14 at 19:51
  • 1
    This is not the problem Robert. In fact, <%=value%> works and shows the real value inside Chart. There is a documentation with properly value like this and how to use it. But legend option does not work and only acepts boolean values. – bcesars Dec 05 '14 at 19:54

2 Answers2

2

Try to remove this line inside datasets:

legend: "Vendas Mensais",
0

I have the same problem remove legend in your code

legend: "Vendas Mensais"

Flw manolo

ErasmoOliveira
  • 1,416
  • 2
  • 20
  • 40