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 に答える