Morris.js bar chart missing labels
Asked Answered
I

1

5

I'm parsing values from a JSON structure into a Morris JS bar chart. The JSON values are loaded via Ajax. The problem is that only every second values is loaded into the x-line (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 is rendered fine, but some labels are missing. I have taken a screenshot.

Link to image

Any suggestions on how to solve this?

Isomer answered 24/11, 2014 at 8:40 Comment(3)
I have exactly same problem, have you fixed it already?Rant
you could also try setting xLabelMargin from #19715804Castleberry
you could also try setting xLabelMargin from #19715804Castleberry
M
10

Morris does this because there is not enough room for the labels. Try adding an angle to the labels, and you shuld be able to see them again.

var params = {
    element: 'myfirstchart',
    data: [],
    xkey: 'year',
    ykeys: ['value'],
    barColors: ['#f46813'],
    labels: ['Rate'],
    xLabelAngle: 60,
};
Merilynmeringue answered 20/2, 2015 at 10:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.