gpt4 book ai didi

javascript - 使用 Extjs 在圆形仪表图中间添加图例

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:13:18 29 4
gpt4 key购买 nike

我使用 extjs 图表系列绘制了一个圆形仪表。我想将仪表的值指示到它的中间,但我没有成功。有没有人可以帮助我?

这是我试过的代码:

{
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'
}*/
}
}

我只想显示该系列的值“10”。在评论中你可以看到我试图添加一个渲染器函数和一个标签属性。在这个标签中,我想我不能写“field:'value'”但是因为我不需要定义一个字段我不知道该用什么。

非常感谢

最佳答案

这是解决方案,您可以在图表的渲染功能上更改您的 Sprite ,然后重绘它,更改 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
}

});

关于javascript - 使用 Extjs 在圆形仪表图中间添加图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39830802/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com