Morris.js histogram is missing labels

I am parsing values ​​from a JSON structure in a Morris JS bar chart. JSON values ​​are loaded via Ajax. The problem is that only every second value is loaded into the x-string (xkeys).

My code:

    <script>
    $( document ).ready(function() {
    $.ajax({
        url: "http://intra.site.com/_vti_bin/ListData.svc/ExchangeRates?$orderby=Modified%20desc",
        headers: { 'accept': 'application/json;odata=verbose', 'content-type': 'application/json;odata=verbose'},
        success: function(data){ 
                    var params = {
                        element: 'myfirstchart',
                        data: [],
                        xkey: 'year',
                        ykeys: ['value'],
                        barColors: ['#f46813'],
                        labels: ['Rate']
                                    };



                        data.d.results.forEach(function(element) {
                        var obj = { "year": element.ExchangeCross, "value": element.ApprovedRate }; 
                        params.data.push(obj);
                    });

                    Morris.Bar(params);

                                }  
            });
});
</script>

      

The chart displays fine, but some labels are missing. I took a screenshot.

Image link

Any suggestions on how to resolve this issue?

+3


source to share


1 answer


Morris does this because there isn't enough space for labels. Try adding an angle to the labels and you can see them again.



var params = {
    element: 'myfirstchart',
    data: [],
    xkey: 'year',
    ykeys: ['value'],
    barColors: ['#f46813'],
    labels: ['Rate'],
    xLabelAngle: 60,
};

      

+7


source







All Articles