![](/img/trans.png)
[英]How can we trigger data point click event in lineseries chart using WinRT XAML Toolkit for Windows Phone 8.1
[英]How to change color of LineSeries in Windows Phone 8.1 XAML ToolKit 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; }
}
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>
如果有人有問題,請在此處使用 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;
只需像這樣修改它:
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;
第一個為我拋出異常,但在使用雙精度值后,它工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.