WPF中的MS图表饼图颜色

编程入门 行业动态 更新时间:2024-10-27 14:31:17
本文介绍了WPF中的MS图表饼图颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用WPF工具包中的数据可视化"内容创建饼图.我已经显示了图表,但是我没有找到一种方法来将切片的颜色设置为我自己的颜色 调色板 (与默认颜色相反)图书馆使用的一种).有人对我该如何做有什么线索吗? 我的数据集中在一个集合中,而调色板中包含一个调色板.字典由数据集合中每个项目都具有的枚举器键入键. 如果可能的话,我希望将其保留为Xaml的* OUT *.

I''m using the Data Visualization stuff in the WPF Toolkit to create a pie chart. I''ve got the chart displaying, but I haven''t found a way to set the colors of the slices to my own color palette (as opposed to the default one used by the library). Does anyone have any clues as to how I can go about doing it? I have my data in one collection, and a colour palette in a dictionary. The dictionary is keyed by an enumerator that each item in the data collection has. I would like to keep it *OUT* of the Xaml if possible.

推荐答案

这就是解决方案.我需要根据值的排序列表设置颜色,并且颜色必须与数据集中的特定类别"(List)匹配.我认为他们成功地使这一点变得晦涩难懂.无法直接设置饼图的颜色-必须通过Chart.Palette属性完成.如果要使用标准以外的其他内容,则必须创建并填充自己的对象.由于我不预先知道将给定类别添加到图表中的顺序,因此我不得不编写一种方法来确定顺序并相应地添加颜色. This was the solution. I needed to set the colors based on a sorted list of values, and the colors had to match a specific "category" in my dataset (a List). I think they succeeded in making this as obscure as possible. There is no way to set the color of a pie slice directly - it MUST be done via the Chart.Palette property. If you want to use something other than the standard you must CREATE and populate your own object. Since I didn''t know ahead of time the order in which a given category was going to be added to the chart, I had to write a method that would determine the order and add colors accordingly. private System.Collections.ObjectModel.Collection<ResourceDictionary> MakePalette(List<RepItem> list) { System.Collections.ObjectModel.Collection<ResourceDictionary> palette = new System.Collections.ObjectModel.Collection<ResourceDictionary>(); foreach (RepItem item in list) { ResourceDictionary rd = new ResourceDictionary(); Style style = new Style(typeof(Control)); SolidColorBrush brush = null; switch (item.Category) { case RepCategory.Author : brush = new SolidColorBrush(Colors.DarkRed); break; case RepCategory.Authority : brush = new SolidColorBrush(Colors.DarkGreen); break; case RepCategory.Debator : brush = new SolidColorBrush(Colors.Magenta); break; case RepCategory.Editor : brush = new SolidColorBrush(Colors.Goldenrod); break; case RepCategory.Enquirer : brush = new SolidColorBrush(Colors.Purple); break; case RepCategory.Organiser : brush = new SolidColorBrush(Colors.Olive); break; case RepCategory.Participant : brush = new SolidColorBrush(Colors.LightSteelBlue); break; } style.Setters.Add(new Setter() { Property = Control.BackgroundProperty, Value = brush }); rd.Add("DataPointStyle", style); palette.Add(rd); } return palette; }

John,我知道您想要xaml的解决方案* OUT *,但我认为这可以提供帮助(在xaml中):样式表 [ ^ ] John, I know you want the solution *OUT* of xaml if possible but I think this can be of help (in xaml): Styling Charts[^]

更多推荐

WPF中的MS图表饼图颜色

本文发布于:2023-06-07 22:05:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/568612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图表   颜色   WPF   MS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!