javascript - 如何将自定义颜色添加到 extjs 条形图

标签 javascript jquery css extjs

我正在尝试使用 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') + '%');
                    }
                }
            }
    ]
});

这是 Jisfiddle

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

最佳答案

在您的 fiddle 中,您使用的是 ExtJS 4.2 那么我假设您使用的是 4.2 verison。要赋予颜色,您必须在 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 属性。

关于javascript - 如何将自定义颜色添加到 extjs 条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44303886/

相关文章:

javascript - 如何通过 Soundcloud API 重复播放歌曲

jquery - 使用 jQueryMobile 滑动时可滚动的 div

css - 忽略 CSS 类中的属性

javascript - 如何在 JSP 中使用 Ajax 保存多条记录

javascript - 使用绝对值创建 Div

javascript - 返回新的 Promise 和 Promise.resolve 的区别

javascript - 为什么要使用 javascript 闭包来实现回调和事件处理程序附件?

javascript - 使用 Bootstrap 的网格系统设计轮廓框

javascript - 如果父级的高度 div 高于 X,则显示此 div

javascript - for循环 react