【问题标题】:Can we add an image in Extjs Scatter chart series?我们可以在 Extjs 散点图系列中添加图像吗?
【发布时间】:2017-11-19 01:22:41
【问题描述】:

我可以看到在 ExtJs 分散的购物车中,我们可以使用不同的标记配置来显示十字、圆形、方形等。但我们可以在其中显示图像或字形吗?

【问题讨论】:

    标签: extjs charts extjs4.2


    【解决方案1】:

    是的,您可以显示图像而不是圆形、正方形等。

    您需要覆盖 Ext.chart.Shape 为您的系列添加其他图像类型。您可以在 ma​​rkerConfig 系列中使用那些定义的类型。

    基本上,您需要定义自己的形状类型,该形状类型将在图表中使用Ext.draw.Sprite 创建。

    这是一个使用 ExtJS 4.2.1.x 的工作示例:

    Ext.application({
        name: 'Fiddle',
    
        launch: function () {
            Ext.override(Ext.chart.Shape, {
                newPhone: function (surface, opts) {
                    return surface.add(Ext.apply({
                        type: 'image',
                        src: 'http://icons.iconarchive.com/icons/igh0zt/ios7-style-metro-ui/512/MetroUI-Other-Phone-icon.png',
                        x: opts.x,
                        y: opts.y,
                        width: 14,
                        height: 14
                    }, opts));
                },
                oldPhone: function (surface, opts) {
                    return surface.add(Ext.apply({
                        type: 'image',
                        src: 'https://cdn3.iconfinder.com/data/icons/communication-1/100/old_phone-512.png',
                        x: opts.x,
                        y: opts.y,
                        width: 14,
                        height: 14
                    }, opts));
                }
            });
    
            var store = Ext.create('Ext.data.JsonStore', {
                fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5'],
                data: [{
                    'name': 'metric one',
                    'data1': 10,
                    'data2': 12,
                    'data3': 14,
                    'data4': 8,
                    'data5': 13
                }, {
                    'name': 'metric two',
                    'data1': 7,
                    'data2': 8,
                    'data3': 16,
                    'data4': 10,
                    'data5': 3
                }, {
                    'name': 'metric three',
                    'data1': 5,
                    'data2': 2,
                    'data3': 14,
                    'data4': 12,
                    'data5': 7
                }, {
                    'name': 'metric four',
                    'data1': 2,
                    'data2': 14,
                    'data3': 6,
                    'data4': 1,
                    'data5': 23
                }, {
                    'name': 'metric five',
                    'data1': 27,
                    'data2': 38,
                    'data3': 36,
                    'data4': 13,
                    'data5': 33
                }]
            });
    
            Ext.create('Ext.chart.Chart', {
                renderTo: Ext.getBody(),
                width: 600,
                height: 600,
                animate: true,
                theme: 'Category2',
                store: store,
                axes: [{
                    type: 'Numeric',
                    position: 'left',
                    fields: ['data2', 'data3'],
                    title: 'Sample Values',
                    grid: true,
                    minimum: 0
                }, {
                    type: 'Category',
                    position: 'bottom',
                    fields: ['name'],
                    title: 'Sample Metrics'
                }],
                series: [{
                    type: 'scatter',
                    markerConfig: {
                        type: 'oldPhone'
                    },
                    axis: 'left',
                    xField: 'name',
                    yField: 'data2'
                }, {
                    type: 'scatter',
                    markerConfig: {
                        type: 'newPhone'
                    },
                    axis: 'left',
                    xField: 'name',
                    yField: 'data3'
                }]
            });
        }
    });
    

    小提琴示例: https://fiddle.sencha.com/#view/editor&fiddle/29rm

    【讨论】:

    • 谢谢你。有效!。考虑到图像质量下降,我想在那里画一条路径。所以我做了一些修改。请找到示例。 fiddle.sencha.com/#view/editor&fiddle/29uj。但传说越来越尴尬。有什么方法可以自定义图例。
    • 我还观察到我们无法为这些自定义精灵添加工具提示!
    • 使用图例属性进行图例配置。图例:{ 位置:'底部',填充:25,边距:0 } 应该修复.. 小提琴示例:fiddle.sencha.com/#view/editor&fiddle/29ur
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    相关资源
    最近更新 更多