简体   繁体   English

尝试在extjs饼图图例文本中显示htmltag字符串

[英]try to display htmltag string in extjs pie chart legend text

before 之前

在此处输入图片说明

after

在此处输入图片说明

my code link (for refrence): https://fiddle.sencha.com/#fiddle/d32 我的代码链接(供参考): https : //fiddle.sencha.com/#fiddle/d32

Use &lt; and &gt; 使用&lt; and &gt; &lt; and &gt; to display < and > symbols respectively in the html page. 分别在html页面中显示<和>符号。

 var store = Ext.create('Ext.data.JsonStore', {
        fields: ['name', 'data'],
        data: [{
            'name': '&lt;test&gt;',
            'data': 10
        }, {
            'name': 'metric two',
            'data': 7
        }, {
            'name': '&lt;metric three&gt;',
            'data': 5
        }, {
            'name': 'metric four',
            'data': 2
        }, {
            'name': 'metric five',
            'data': 27
        }]
    });

在此处输入图片说明

This is simple HTML fix. 这是简单的HTML修复程序。 ExtJS does not have anything to do with this. ExtJS与此无关。 What ExtJS does in displaying the lengend is, ExtJS takes the value in the 'name' attribute of the store-->data part and embeds it to the HTML span tag as, ExtJS在显示字符时所做的就是,ExtJS在store-> data部分的'name'属性中获取值,并将其嵌入到HTML span标签中,如下所示:

['<div class="', Ext.baseCSSPrefix, 'legend-container">', '<tpl for=".">', '<div class="', Ext.baseCSSPrefix, 'legend-item">', '<span ', 'class="', Ext.baseCSSPrefix, 'legend-item-marker {[ values.disabled ? Ext.baseCSSPrefix + \'legend-inactive\' : \'\' ]}" ', 'style="background:{mark};">', '</span>{name}', '</div>', '</tpl>', '</div>']

see here 看这里

You might also want to take a look over entity characters in html 您可能还想看看html中的实体字符

You will have to do html encoding of data before binding it to the store. 在将数据绑定到商店之前,您将需要对数据进行html编码。 Try this. 尝试这个。

var holdData = [{
    'name': '<test>',
    'data': 10
 }, {
    'name': 'metric two',
    'data': 7
 }, {
   'name': '<metric three>',
   'data': 5
 }, {
   'name': 'metric four',
   'data': 2
 }, {
   'name': 'metric five',
   'data': 27
}];

holdData.map(function(d){ d.name=Ext.util.Format.htmlEncode(d.name); return d; });

var store = Ext.create('Ext.data.JsonStore', {
   fields: ['name', 'data'],
   data: holdData
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM