簡體   English   中英

wpf不同顏色的面積圖?

[英]wpf Area Chart with Different Colors?

我是一個沉思MS工具包圖表,無法弄清楚如何改變區域的顏色。 我需要動態填充圖表,這意味着我不知道區域圖表將有多少部分。

這是我的代碼。

var a = new AreaSeries
{
  Title = "a",
  IndependentValuePath = "Key",
  DependentValuePath = "Value",
  Background = Brushes.Plum
};

我試圖改變前景和背景,沒有骰子。

mcChart.Series.Add(a);

a = new AreaSeries
{
  Title = "b",
  IndependentValuePath = "Key",
  DependentValuePath = "Value",
  Background = Brushes.Peru
};

mcChart.Series.Add(a);

填寫圖表。

((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的新手,我無法弄清楚這有什么問題。

這是XAML

<chartingToolkit:Chart 
  Width="600" Height="450"
  Name="mcChart" 
  Background="LightBlue"
  Foreground="DarkBlue"
  Title="Area Chart">                
</chartingToolkit:Chart>

如何更改區域a和區域b的顏色。 現在,即使我設置了背景和前景,它們也是默認的顏色。

謝謝。

您可以使用Chart.Palette屬性,如下所示:

<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>
  • 是一些更多的信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM