Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

javascript - Legend and Bar Chart Colors do not match

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 bound somehow, how should I fix it?

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

dataSample:

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

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

js fiddle

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;
            }
         }
     },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...