图例和条形图颜色不匹配 [英] Legend and Bar Chart Colors do not match

查看:391
本文介绍了图例和条形图颜色不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下实现,我使用colorField来指定颜色。但是,即使我正确地为条形图堆栈对象着色,但此颜色与图例颜色不匹配。我认为它应该以某种方式绑定,我应该如何解决它?

I have the following implementation and I used colorField to assign colors. However, even though I color the bar stack objects properly, but this color does not match with legend color. I thought it should be binded somehow, how should I fix it?

我使用了 colorField ,因为我想要为条形堆栈列中的配对对象指定相同的颜色。

I have used colorField, because I want to assign same color for paired objects in bar stack column.

dataSample:

dataSample:

data[0] = {
    "value": 29,
    "series": 1,
    "category": "Men",
    "fname": "NY",
    "valueColor": "black"
}, 

< img src =https://i.stack.imgur.com/5itV6.pngalt =在此处输入图像说明>

http://jsfiddle.net/fm79hsms/13/

推荐答案

这是一个解决方案,虽然它有点像hacky。

Here is a solution, although it feels kind of hacky.

js小提琴

我使用legend.item.visual重绘图例并从数据中拉入valueColor,很好地传递给了legened.item.visual功能离开。

I used legend.item.visual to redraw the legend and pulled in the valueColor from the data, which was nicely passed along to the legened.item.visual function.

legend: {
        item: {
            visual: function (e) {

                var color = ""

                for (var i=0;i<e.series.data.length;i++){
                    if (e.series.data[i].valueColor != "" && e.series.data[i].fname != "") {
                    color = e.series.data[i].valueColor
                    }
                }

              var rect = new kendo.geometry.Rect([0, 0], [100, 50]);
              var layout = new kendo.drawing.Layout(rect, {
                spacing: 5,
                alignItems: "center"
              });

              var marker = new kendo.drawing.Path({
                fill: {
                  color: color
                }
              }).moveTo(10, 0).lineTo(10, 10).lineTo(0, 10).lineTo(0,0).close();

              var label = new kendo.drawing.Text(e.series.name, [0, 0], {
                fill: {
                  color: "black"
                }
              });

              layout.append(marker, label);
              layout.reflow()

              return layout;
            }
         }
     },

这篇关于图例和条形图颜色不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆