Search code examples
javagxt

Sencha GXT4 : How to display text inside a pie chart?


I'm developing an application with the GWT framework and Sencha GXT on the front-end. I managed to display some data in a pie chart but I would also like to have a label inside the donut pie chart like this image. I looked at the demo provided by sencha as well as the "Chart" class but I don't see any cases where there is text inside a pie chart. Is it feasible ?

I'm using "Sencha GXT 4.0.0 - Sencha for GWT"


Solution

  • I finally found a solution, I just need to use the setX method in my textConfig so my code looks something like this :

    TextSprite textConfig = new TextSprite();
    textConfig.setFont("Arial");
    textConfig.setTextBaseline(TextBaseline.MIDDLE);
    textConfig.setFontSize(18);
    textConfig.setTextAnchor(TextAnchor.MIDDLE);
    textConfig.setZIndex(15);
    textConfig.setX(-150);
    

    150 worked for me but maybe it won't for you.