Is it possible to add title to charts?

后端 未结 5 1349
傲寒
傲寒 2021-02-13 12:39

I want to add a title to a chart, like in the gauge example or a pie chart. I want to display a title under or on top of the chart. Is this possible? I\'ve been looking and can\

相关标签:
5条回答
  • 2021-02-13 13:15

    Since Ext.chart.Chart is an Ext.draw.Component, you can add sprites as items of it. Try to use this:

    Ext.create('Ext.chart.Chart', {
       default chart settings here
    
       ...
    
       items: [{
          type  : 'text',
          text  : 'Simple Title',
          font  : '14px Arial',
          width : 100,
          height: 30,
          x : 50, //the sprite x position
          y : 10  //the sprite y position
       }]
    })
    
    0 讨论(0)
  • 2021-02-13 13:17

    Just put your chart inside a panel with the title you need.

    Ext.create('Ext.panel.Panel', {
        title: 'My Title',
        layout: 'fit',
        items: yourChart
    });
    
    0 讨论(0)
  • 2021-02-13 13:22

    I'd recommend not using a sprite since you'll likely want the title centered. Any changes to the container size or your text length won't be automatically handled since the sprite approaches described in other answers here all hardcode the location. Centering with a sprite can be done with some effort but I'd consider leveraging the layout system. This way your page contents can automatically be positioned nicely when your page resizes.

    // Use a vbox layout with whatever options you need
    layout: {
        type: 'vbox',
        align: 'center'
    },
    items: [{
        type: 'container',
        html: 'My Title'
    },{
        type: 'chart',
        flex: 1,
        // ...etc
    }];
    
    0 讨论(0)
  • 2021-02-13 13:28

    Yes you can using Ext.chart.axis.Gauge. Inside items put an axis config with a title:

    Ext.create('Ext.chart.Chart', {
       default chart settings here
    
       ...
    
       items: [{
                    axes: [
                        {
                            position: 'gauge',
                            type: 'Gauge',
                            title: 'Net Pips',
                            maximum: 500,
                            minimum: 0
                        }
                    ]
       }]
    })
    
    0 讨论(0)
  • 2021-02-13 13:29

    You can simply add a sprite to the cart.surface:

    var chart = Ext.create('Ext.chart.Chart', {
        ... default chart settings here ...
    });
    var sprite = Ext.create('Ext.draw.Sprite', {
        type: 'text',
        surface: chart.surface,
        text: 'Simple text',
        font: '12px Arial',
        x: 50,
        y: 0,
        width: 100,
        height: 100 
    });
    sprite.show(true);
    chart.surface.add(sprite);
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题