javascript - 无法编辑 Ext 图表中的自定义文本项

标签 javascript extjs charts

我有一个用 Ext js 制作的图表。该图表有一些自定义文本项。我想动态更改这些文本。我希望将这些文本组件作为 svg 的一部分,因为导出的图表图像也应包含这些自定义文本。 JSFiddle

Ext.onReady(function() {
    Ext.define("PopulationPoint", {
        extend: "Ext.data.Model",
        fields: [ "state", "population" ]
    });
    var a = Ext.create("Ext.draw.Text", {
        type: "text",
        text: "Initial Text",
        font: "24px Arial",
        width: 500,
        height: 100,
        x: 20,
        y: 20
    });
    var b = Ext.create("Ext.data.Store", {
        model: "PopulationPoint",
        data: [ {
            state: "Alabama",
            population: 4802740
        }, {
            state: "Alaska",
            population: 722718
        }, {
            state: "Arizona",
            population: 6482505
        }, {
            state: "Arkansas",
            population: 2937979
        }, {
            state: "California",
            population: 37691912
        }, {
            state: "Colorado",
            population: 5116796
        }, {
            state: "Connecticut",
            population: 3580709
        }, {
            state: "Delaware",
            population: 907135
        }, {
            state: "DC",
            population: 617996
        } ]
    });
    Ext.create("Ext.chart.Chart", {
        renderTo: Ext.getBody(),
        width: 470,
        height: 400,
        store: b,
        items: [ a ],
        series: [ {
            type: "pie",
            field: "population",
            label: {
                field: "state",
                display: "outside",
                font: "12px Arial"
            }
        } ]
    });
    setInterval(function() {  
        a.setText("NewText"); // This statement has no use
    }, 3e3);
 });

有人知道怎么解决吗?提前致谢。

更新

当我使用 Ext.draw.Sprite 而不是 Ext.draw.Text 时它起作用了。但仍然导出的图表图像包含旧文本。更新 Jsfiddle

var txtDraw =  Ext.create('Ext.draw.Sprite', {
    type:'text',
    text  : 'Initial Text',
    font  : '24px Arial',
    width : 500,
    height: 100, 
    x:20,
    y:20
});

最佳答案

txtDraw.setAttributes({ 'text':'Jeff'},true )

使用Ext.draw.Sprite的setAttributes方法

引用 - http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.draw.Sprite-method-setAttributes

关于javascript - 无法编辑 Ext 图表中的自定义文本项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28409620/

相关文章:

javascript - 使用 TypeScript 和 controllerAs 将方法附加到 Controller

sencha-touch - Sencha xtype 方法

javascript - 与桌面浏览器兼容的 HTML5 移动框架

javascript - Ext js对齐文本框输入框

javascript - Highcharts 区域范围draggableHigh 和draggableLow 不起作用

javascript - 在 d3.js 中更新饼图

javascript - 根据选定的复选框和选择字段过滤数组

javascript - 检查是否选择了 optgroup 中的部分或全部选项

javascript - 绑定(bind)/取消绑定(bind)事件或使用条件(jQuery)更好吗?

javascript - 如何在调整 Chart.js/canvas 大小时修复背景渐变