0

我正在尝试从代码后面设置图表中某条线的颜色。我已经搜索了 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; }
    }
4

1 回答 1

1
 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>
于 2015-06-12T22:04:37.670 回答