Ticket #7746 (new enhancement)

Opened 3 months ago

Proposal to add axis title

Reported by: enzo Owned by: elazutkin
Priority: normal Milestone: tbd
Component: Charting Version: 1.2beta
Severity: normal Keywords:
Cc: ttrenka

Description

Titles for axes used to be available, but they became collateral damage in the transition to the new charting engine. As I needed them, I slightly modified the code contributed by jmarca at http://www.dojotoolkit.org/forum/dojo-foundation/general-discussion/how-add-name-axes-im-not-able , and found the result quite convenient and useful. What about including this code in the dojox.charting package? The function to add is:

var setAxisTitle=function(chart, axisname, title, fontsizept) {
    var axis = chart.axes[axisname];
    var dim = chart.dim;
    var offsets=chart.offsets;
    var ta = chart.theme.axis;
    var taFont = "font" in axis.opt ? axis.opt.font : ta.font;
    var x;
    var y;
    var label;
    var rotate=0;
    if(axis.vertical) {
        rotate=270
        label = title;
        y=dim.height/2  - offsets.b/2;
        x=0+2*fontsizept;
    } else {
        label = title;
        x=dim.width/2 + offsets.l/2;
        y=dim.height-fontsizept/2;
    }
    var m = dojox.gfx.matrix;
    var elem = axis.group.createText({x:x, y:y, text:label, align: "middle"});
    elem.setFont({family:taFont.family, size: fontsizept+"pt", weight: "bold"});
    elem.setFill('grey');
    elem.setTransform(m.rotategAt(rotate, x,y));
}

...and it can be called AFTER the rendering with code like:

mychart.render();
setAxisTitle(mychart,"x","Title for X axis",10);
setAxisTitle(mychart,"y","Title for Y axis",10);
Note: See TracTickets for help on using tickets.