Add legend in the middle of a pie chart with Extjs

I drew a circular gauge using a series of extjs diagrams. I would like to indicate the sensor value in the middle, but I do not succeed. Can anybody help me?

Here is the code I tried:

{
    xtype: 'polar',
    width: 60,
    height: 60,
    background: '#00c6c9',
    style: {left:0, right:0},
    series: {
            type: 'gauge',
            minimum: 0,
            maximum: 30,
            value: 10,
            colors: ['#25a2b6', 'lightgrey'],
            donut: 75,
            background: '#00c6c9',
            totalAngle: Math.PI * 2,
            style: {left:0, right:0},
            needleLength: 100
            /*,
            renderer: function(sprite, record, attributes, index, store) {
                var sprite2 = Ext.create('Ext.draw.Sprite', {
                type: 'text',
                text: Math.floor(attributes.value),
                font: '16px Arial',
                x: 30,
                y: 30
                });
                sprite2.show(true);    
                return attributes;
            },
            label: {
                field: 'value',
                display: 'middle'
            }*/
    }
}

I just want to show the meaning of the "10" series. In the comments, you can see that I tried to add a rendering function and a label property. On this label, I think I can not write "field: 'value", but since I do not need to define a field, I do not know what to use.

Many thanks

+4
source share
1 answer

, , , x, y, .

Ext.create({
    xtype: 'polar',
    renderTo: document.body,
    width: 160,
    height: 160,
    background: '#00c6c9',
    style: {
        left: 0,
        right: 0
    },
    listeners:{
        render: function(chart){
            var sprite=Ext.clone(chart.getSprites()[0]);
            //modify sprite here
            sprite.text=''+chart.getSeries()[0].config.value;
            chart.setSprites(sprite);
            chart.redraw();
        }
    },
    sprites: [{
        type: 'text',
        x: 58,
        y: 95,
        text: 'test',
        fontSize: 40,
        fillStyle: 'white'
    }],
    series: {
        type: 'gauge',
        minimum: 0,
        maximum: 30,
        value: 10,
        colors: ['#25a2b6', 'lightgrey'],
        donut: 75,
        background: '#00c6c9',
        totalAngle: Math.PI * 2,
        style: {
            left: 0,
            right: 0
        },
        needleLength: 100
    }

    });
+2

Source: https://habr.com/ru/post/1656575/


All Articles