WPF 工具包饼图样式颜色
我想在饼图中的每个饼图切片的代码隐藏中设置颜色。有人知道该怎么做吗?现在它从样式 xaml 获取颜色,但我需要自己从代码隐藏中为每个值(饼图切片)分配颜色。
i`d like to set colors in codebehind for every Pie Slice in my PieChart. Anyone knows how to do this? Now it gets the colors from the styles xaml, but i need to assign the colors for each value (pie slice) by myself from codebehind.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这是否是最好的方法,但我在同样的事情上挣扎并最终让它像这样工作。
声明一个调色板:
然后使用颜色信息创建一个(或多个)画笔:
对于每个画笔,创建一个新样式并将其添加到调色板集合中:
请注意,必须将每个画笔(或调色板条目)创建为新的 ResourceDictionary目的。如果您创建 10 个画笔并将它们全部添加到同一个 ResourceDictionary 中,则饼图将仅使用第一种颜色。 (或者也许我只是做错了什么)。
然后将图表调色板设置为自定义调色板:
这仅在您想要将调色板自定义为特定颜色时才有用。对于颜色范围或固定的颜色列表,我相信您可以在 XAML 中定义调色板。
希望有帮助。
Not sure if this is the best way of doing it but I struggled with the same thing and eventually got it working like this.
Declare a palette:
Then create a brush (or brushes) with the color information:
With each brush, create a new Style and add it to the palette collection:
Note that each brush (or palette entry) has to be created as a new ResourceDictionary object. If you create 10 brushes and just add them all to the same ResourceDictionary the piechart will only use the first color. (Or maybe I'm just doing something wrong).
Then set the chart palette to the custom palette:
This is only useful if you want to customise the palette to specific colors. For a color range or fixed list of colors I believe you can just definie the palette in XAML.
Hope it helps.
一种可能是从 HSL 或 HSV 构建颜色,保持 SL/SV 部分固定,您可以划分整个色调范围到你拥有的饼片数量,这应该确保它们在视觉上合理分离。不同的 SL/SV 值将使图表颜色鲜艳、柔和或深色等。
One possiblitiy is to construct your colours from HSL or HSV, keeping the SL/SV part fixed you can divide the entire hue range into the number of pie slices you have, this should ensure they are reasonably visually seperated. different SL/SV values will make the chart vibrant colours or pastels or dark shades etc.