Extjs更改堆积条形图中条形的颜色

发布于 2024-11-15 23:44:46 字数 533 浏览 4 评论 0原文

让我们以这个示例...如何改变那些条的颜色?

我知道我可以通过渲染器更改它,但它不会改变图例。

我尝试使用:

style: {fill: 'red'}

的每个条的颜色

但它改变了我尝试将颜色放入数组中

,但它不起作用。我尝试将每种样式放入数组中,如下所示:

style: [{fill: 'red'}, {fill: 'green'}, {fill: 'blue'}]

但它也不起作用,因为我可以将标题放入数组中,例如:

title: ['title1', 'title2', 'title3']

我认为它(样式)也应该起作用,但不行。

那么如何更改每个“数据”栏的颜色?

let's take this example... how to change colors of those bars?

I know I can change it via renderer but it won't change legend.

I have tried to use:

style: {fill: 'red'}

but it changes color of ever bar

I have tried to put colors in array, its not working.

I have tried to put each style in array, like this:

style: [{fill: 'red'}, {fill: 'green'}, {fill: 'blue'}]

But it won't work either, since I can put titles in array like:

title: ['title1', 'title2', 'title3']

I thought it (styles) should work too but not.

So how can I change color of each "data" bar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

握住我的手 2024-11-22 23:44:46

条形颜色实际上由图表主题决定:

Ext.create('Ext.chart.Chart', {
    theme: 'myTheme'
    //the remainder of your code...
});

为了使用自定义颜色,您需要扩展现有的“Base”主题,如 自定义面积图示例

Bar colors are actually determined by the chart's theme:

Ext.create('Ext.chart.Chart', {
    theme: 'myTheme'
    //the remainder of your code...
});

In order to use custom colors, you will need to extend the existing 'Base' theme, as in the custom area chart example.

春花秋月 2024-11-22 23:44:46

Chart 使用 Theme 作为 mixins,

因此您可以直接使用名为 themeAttrs 的主题属性。

例如,如果您在柱形图/堆积柱形图的构造函数中,想要更改柱形的颜色,您可以指定

this.themeAttrs.colors = ['#F2C72B','#a5c249','#E88712','#9D5FFA'];

Chart uses Theme as mixins

So you can directly use theme property called themeAttrs.

For example if you are in constructor of column/stacked column chart, want to change the color of columns You can specify

this.themeAttrs.colors = ['#F2C72B','#a5c249','#E88712','#9D5FFA'];
伪装你 2024-11-22 23:44:46
Ext.onReady(function() 
{

  Ext.create('Ext.window.Window', 
  {
    title: 'Pie1 Chart',
    height: 400,
    layout: 'fit',
    width: 400,
    items: 
    [{
      xtype: 'chart',
      animate:false ,
      insetPadding:0,

      legend: 
    {
        position: 'right'
        },
      shadow: true,
      store: 
    {
        fields: 
    [{
          name: 'category', type: 'string'
        },

    {
          name: 'data', type: 'float'
        }],
        data: 
    [{
          category: 'Alive', data: 1.5
        },{
          category: 'Dead', data: 2 
        },{
          category: 'Standby', data: 1
        }]
      },
      series: [{
        type: 'pie',
        field: 'data',
     colorSet: ['#0000FF','#FFffff','#00FF00'],

        showInLegend: true, <!--It is use to display data in which color.-->
        highlight: {
          segment: {
            margin: 20
          }
        },
        label: {
          field: 'category',
          display: 'rotate',
          contrast: true,
          font: '18px Arial'
        }
      }]
    }]
  }).show();  
});

使用 colorSet 你可以改变颜色。

Ext.onReady(function() 
{

  Ext.create('Ext.window.Window', 
  {
    title: 'Pie1 Chart',
    height: 400,
    layout: 'fit',
    width: 400,
    items: 
    [{
      xtype: 'chart',
      animate:false ,
      insetPadding:0,

      legend: 
    {
        position: 'right'
        },
      shadow: true,
      store: 
    {
        fields: 
    [{
          name: 'category', type: 'string'
        },

    {
          name: 'data', type: 'float'
        }],
        data: 
    [{
          category: 'Alive', data: 1.5
        },{
          category: 'Dead', data: 2 
        },{
          category: 'Standby', data: 1
        }]
      },
      series: [{
        type: 'pie',
        field: 'data',
     colorSet: ['#0000FF','#FFffff','#00FF00'],

        showInLegend: true, <!--It is use to display data in which color.-->
        highlight: {
          segment: {
            margin: 20
          }
        },
        label: {
          field: 'category',
          display: 'rotate',
          contrast: true,
          font: '18px Arial'
        }
      }]
    }]
  }).show();  
});

using colorSet you can change color.

梦忆晨望 2024-11-22 23:44:46

我决定添加完整代码:

Ext.require('EAM.view.chart.*');
Ext.define('EAM.view.chart.integral.IntegralChart',
{
    extend : 'Ext.chart.Chart',
    alias : 'widget.GroupsIntegralChart',
    animate : true,
    shadow : true,
    // theme : 'Browser:gradients',

    initComponent : function()
    {
        var me = this;
        me.themeAttrs.colors =
        [
            'orange',
            'red',
            'blue',
            'green',
        ];
        me.callParent(arguments);
    },
...

I decided add full code:

Ext.require('EAM.view.chart.*');
Ext.define('EAM.view.chart.integral.IntegralChart',
{
    extend : 'Ext.chart.Chart',
    alias : 'widget.GroupsIntegralChart',
    animate : true,
    shadow : true,
    // theme : 'Browser:gradients',

    initComponent : function()
    {
        var me = this;
        me.themeAttrs.colors =
        [
            'orange',
            'red',
            'blue',
            'green',
        ];
        me.callParent(arguments);
    },
...
一桥轻雨一伞开 2024-11-22 23:44:46

如果你不想使用主题,你可以使用这个(至少它对我有用):

this.series = [{
type: 'column',
axis: 'left',
showInLegend : true,
xField: 'f1',
style :{
    fill :  '#ff00ff',
    'stroke-width': 3,
    width: 20
},
renderer: function(sprite, storeItem, barAttr, i, store) {
    barAttr.fill = '#ff00ff';
    barAttr.width = 20;
    return barAttr;
},
title : 'title',
yField: 'f2'
}]

请注意,你必须将你的颜色放在两个不同的行中(我认为ExtJS有时有点愚蠢的框架)。

If you don't want to use a theme, you can use this (at least it worked for me):

this.series = [{
type: 'column',
axis: 'left',
showInLegend : true,
xField: 'f1',
style :{
    fill :  '#ff00ff',
    'stroke-width': 3,
    width: 20
},
renderer: function(sprite, storeItem, barAttr, i, store) {
    barAttr.fill = '#ff00ff';
    barAttr.width = 20;
    return barAttr;
},
title : 'title',
yField: 'f2'
}]

Note that you have to put your color in two different lines (I think ExtJS is sometimes kinda stupid framework).

听,心雨的声音 2024-11-22 23:44:46

我正在使用 Ext JS 5.0
无需担心,只需串联包含颜色配置即可。

series : [{
        type : 'bar',
        colors:['#f23f3f','#ff8809','#ff0','#0039a6','#00ee88','#ff8aed'],
        xField : ['Q1']
        yField : ['Critical', 'Major', 'Minor', 'Warning', 'Informational',   'Indeterminent']
}]

I'm using Ext JS 5.0
There is no need to worry,just include colors config in series.

series : [{
        type : 'bar',
        colors:['#f23f3f','#ff8809','#ff0','#0039a6','#00ee88','#ff8aed'],
        xField : ['Q1']
        yField : ['Critical', 'Major', 'Minor', 'Warning', 'Informational',   'Indeterminent']
}]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文