2015-06-12 72 views
0

我試圖從代碼後面的圖表中某行的顏色設置。我已經搜索了3個小時怎麼做,我找不到任何東西。這有可能做到嗎?如果它不能做到,請推薦另一個圖表庫,我可以做到這一點。如何更改Windows Phone 8.1 XAML ToolKit圖表中LineSeries的顏色?

謝謝!

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
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> 
+0

奧拉魯米爾恰感謝! XAML不起作用我收到錯誤,如成員「DataPointStyle」無法識別或無法訪問。 第一個選項工作,但僅限於線上的點,它會改變點的顏色而不是線的顏色。你知道如何改變它嗎? – Icet

相關問題