Search code examples
raphaellinechartgraphael

g.Raphael Hide y-axis label in


I add a line chart with g.Raphael.js like so:

var tl = paper.linechart(x, y, w, h, [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [trendline], { axis: "0 0 0 1", colors:['#fff'] });

Sometimes, "trendline" will be an empty array, which results in Y-axis labels of "NaN" and "Infinity". How can I hide those labels in those cases? I've tried playing with axisystep but that didn't make a difference. Perhaps line chart could use a "axisylabels" setting like the dots chart has?


Solution

  • I think you could do the following to hide the labels in such cases:

    var chart = paper.linechart(x, y, w, h,
        [[1,2,3,4,5,6,7,8,9,10]], [trendline],
        { axis: "0 0 0 1", colors:['#fff'] });
    
    // hide labels if there is no data
    if (trendline.length == 0) {
        var y_labels = chart.axis[0].text.items;
        for (var i in y_labels) {
            y_labels[i].attr({'text': ""});
        };
    }