WPF面积图用不同的颜色? [英] wpf Area Chart with Different Colors?
问题描述
我一个沉思的MS工具包,图表和无法弄清楚如何改变区域的颜色。我需要填充动态图表,这意味着我不知道时间提前面积图有多少段有。
I a musing the MS toolkit charts and cannot figure out how to change the color of the areas. I need to populate the chart dynamically which means I do not know ahead of time how many sections the area chart will have.
下面是我的代码。
var a = new AreaSeries
{
Title = "a",
IndependentValuePath = "Key",
DependentValuePath = "Value",
Background = Brushes.Plum
};
我试图同时改变富勒地面和背景,没有骰子。
I have tried to change both the Fore Ground and Background and no dice.
mcChart.Series.Add(a);
a = new AreaSeries
{
Title = "b",
IndependentValuePath = "Key",
DependentValuePath = "Value",
Background = Brushes.Peru
};
mcChart.Series.Add(a);
填写图表。
Fill the chart.
((AreaSeries)mcChart.Series[0]).ItemsSource = new[]
{
new KeyValuePair<string, int>("1", 100),
new KeyValuePair<string, int>("2", 180),
new KeyValuePair<string, int>("3", 110),
new KeyValuePair<string, int>("4", 95),
new KeyValuePair<string, int>("5", 40),
new KeyValuePair<string, int>("6", 95)
};
((AreaSeries)mcChart.Series[1]).ItemsSource = new[]
{
new KeyValuePair<string, int>("1", 150),
new KeyValuePair<string, int>("2", 280),
new KeyValuePair<string, int>("3", 310),
new KeyValuePair<string, int>("4", 195),
new KeyValuePair<string, int>("5", 340),
new KeyValuePair<string, int>("6", 195)
};
我是新来WPF和我无法弄清楚什么是错。
I am new to wpf and I cannot figure out what is wrong with this.
下面是XAML
<chartingToolkit:Chart
Width="600" Height="450"
Name="mcChart"
Background="LightBlue"
Foreground="DarkBlue"
Title="Area Chart">
</chartingToolkit:Chart>
如何更改区域和区域B的颜色。现在他们是曾经的颜色是默认的,即使我设置的背景和前景。
How do I change the color of area a and area b. Right now they are what ever color is default even though I set the background and foreground.
感谢。
推荐答案
您可以使用 Chart.Palette
属性是这样的:
You can use the Chart.Palette
property like this:
<Grid>
<charting:Chart>
<charting:Chart.Palette>
<visualizationToolkit:ResourceDictionaryCollection>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="MistyRose"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="AliceBlue"/>
</Style>
</ResourceDictionary>
</visualizationToolkit:ResourceDictionaryCollection>
</charting:Chart.Palette>
<charting:AreaSeries Title="Series 1"/>
<charting:AreaSeries Title="Series 2"/>
</charting:Chart>
</Grid>
- 的Here 是一些信息
- Here is some more information.
这篇关于WPF面积图用不同的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!