我有一个用 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/