繁体   English   中英

如何向extjs条形图添加自定义颜色

[英]How to add custom color to extjs bar chart

我正在尝试使用extjs条形图向条形图添加自定义颜色和其他样式,我希望在插件属性中完成样式,方法请参阅第一个系列。 这是我的代码

Ext.require([
    'Ext.chart.Chart'
]);

Ext.define('CricketScore', {
    extend: 'Ext.data.Model',
    fields: ['month', 'data1' ]
});

var store = Ext.create('Ext.data.Store', {
    model: 'CricketScore',
            data: [
                { month: 'Jan', data1: 20 },
                { month: 'Feb', data1: 20 },
                { month: 'Mar', data1: 19 },
                { month: 'Apr', data1: 18 },
                { month: 'May', data1: 18 },
                { month: 'Jun', data1: 17 },
                { month: 'Jul', data1: 16 },
                { month: 'Aug', data1: 16 },
                { month: 'Sep', data1: 16 },
                { month: 'Oct', data1: 16 },
                { month: 'Nov', data1: 15 },
                { month: 'Dec', data1: 15 }
            ]
});

Ext.create('Ext.chart.Chart', {
   //renderTo: Ext.getBody(),
   renderTo: "demoChart",
   width: 400,
   height: 300,
    store: store,
    animate: true,
   axes: [
       {
                type: 'Numeric',
                position: 'bottom',
                fields: ['data1'],
                minimum: 0,
                maximum:100

            }, {
                type: 'Category',
                position: 'top',
                fields: ['month'],
            }
    ],

      series: [
       {
                type: 'column',
                axis: 'left',
                xField: 'month',
                yField: 'data1',
                style :{
                    fill : '#343234',
                    'stroke-width': 30
                },
                highlight: {
                    fill: '#cd1c5f',
                    'stroke-width': 10,
                    stroke: '#ed2b74'
                },
                tips: {
                    trackMouse: true,
                    style: 'background: #FFF',
                    height: 20,
                    renderer: function(storeItem, item) {
                        this.setTitle(storeItem.get('month') + ': ' + storeItem.get('data1') + '%');
                    }
                }
            }
    ]
});

这是吉斯提德

http://jsfiddle.net/djaydxnd/54/

在您的小提琴中,您使用的是ExtJS 4.2然后假设您使用的是4.2版本。 要赋予颜色,您必须在series对象中编写renderergetLegendColor函数

getLegendColor: function(index) {
                return 'rgb(255,203,36)';
              },
renderer: function(sprite, record, attr, index, store) {
                return Ext.apply(attr, {
                 fill: 'rgb(255,203,36)'
                });
              }

希望这可以帮助。

ExtJA 6您可以直接使用series对象的colors属性。

暂无
暂无

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

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