[英]How to change color of LineSeries in Windows Phone 8.1 XAML ToolKit Chart?
I'm trying to set from the Code Behind a color of some line in Chart.我正在尝试从代码背后设置图表中某行的颜色。 I have searched for 3 hours how to do it and I couldn't find anything.我已经搜索了 3 个小时如何去做,但我找不到任何东西。 Is it possible do to that?有可能这样做吗? If it can't be do, please recommend another chart library where I can do that.如果做不到,请推荐另一个我可以做到的图表库。
Thanks!谢谢!
XAML 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 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; }
}
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;
Have you tried this? 你有尝试过吗? Try to set it when you get the line here 当您到达此处时尝试设置它
(LineChart.Series[0] as LineSeries).DataPointStyle = style;
You may also try the following XAML: 您也可以尝试以下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>
If anyone has problems, with Olaru Mircea solution in here如果有人有问题,请在此处使用 Olaru Mircea 解决方案
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;
just modify it like this:只需像这样修改它:
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.0));
style.Setters.Add(new Setter(Control.WidthProperty, 5.0));
series.DataPointStyle = style;
The first threw an exception for me, but after using double values, it worked fine.第一个为我抛出异常,但在使用双精度值后,它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.