如何在Windows Phone 8.1 XAML ToolKit Chart中更改LineSeries的颜色?

时间:2015-06-12 17:19:12

标签: c# wpf charts windows-phone-8.1 winrt-xaml-toolkit

我正在尝试从Chart中设置Chart中某些线条的颜色。我搜索了3个小时怎么做,我找不到任何东西。有可能吗?如果无法做到,请推荐另一个图表库,我可以这样做。

谢谢!

XAML

<Charting:Chart Title="Name" x:Name="LineChart" HorizontalAlignment="Left" VerticalAlignment="Center"  Width="510" Height="450">
        <Charting:LineSeries Title="PB" IndependentValuePath="Name" DependentValuePath="Amount" IsSelectionEnabled="True"/>
        <Charting:LineSeries Title="Oil" IndependentValuePath="Name" DependentValuePath="Amount" IsSelectionEnabled="True"/>
    </Charting:Chart>

WPF

Random rand = new Random();
        List<FinancialStuff> financialStuffList = new List<FinancialStuff>();
        for (int i = 0; i < 30; i++ )
            financialStuffList.Add(new FinancialStuff() { Name = Convert.ToString(i), Amount = rand.Next(0, 200) });

        (LineChart.Series[0] as LineSeries).ItemsSource = financialStuffList;

        for (int i = 0; i < 30; i++)
            financialStuffList[i].Amount = rand.Next(0, 50);
        (LineChart.Series[1] as LineSeries).ItemsSource = financialStuffList;



public class FinancialStuff
    {
        public string Name { get; set; }
        public int Amount { get; set; }
    }

1 个答案:

答案 0 :(得分:2)

 Style style = new Style(typeof(Control));
 style.Setters.Add(new Setter(Control.BackgroundProperty, new  SolidColorBrush(Colors.Red)));
 style.Setters.Add(new Setter(Control.HeightProperty, 5));
 style.Setters.Add(new Setter(Control.WidthProperty, 5));
 series.DataPointStyle = style;
你试过这个吗?当你在这里获得这条线时尝试设置它

 (LineChart.Series[0] as LineSeries).DataPointStyle = style;  

您也可以尝试以下XAML:

<charting:LineSeries.DataPointStyle>
   <Style TargetType="charting:LineDataPoint">
       <Setter Property="Width" Value="17" />
       <Setter Property="Height" Value="17" />
       <Setter Property="Background" Value="Lime"/>
   </Style>
</charting:LineSeries.DataPointStyle>