前提・実現したいこと
OxyPlotというライブラリを用いてWPFアプリケーションを作っています。
散布図のグラフの色を変えたいのですが、変えられず困っています。
デフォルトでは緑色になっているようですが、他の色に変えたいです。
該当のソースコード
サンプルで作っているので中途半端なMVVMですがご容赦下さい。
C#
1//MainWindow - Codebehind 2using System; 3using System.Collections.Generic; 4using System.Windows; 5using OxyPlot; 6using OxyPlot.Series; 7using OxyPlot.Axes; 8 9 public partial class MainWindow : Window 10 { 11 private MainViewModel mMainViewModel; 12 13 private int count = 0; 14 ScatterSeries mPoint = null; 15 16 public MainWindow() 17 { 18 InitializeComponent(); 19 mMainViewModel = new MainViewModel(); 20 this.DataContext = mMainViewModel; 21 } 22 23 private void OnClicOpenSubWindow(object sender, RoutedEventArgs e) 24 { 25 mMainViewModel.ChartList.Series.Add(mPoint); 26 27 SubWindow subWindow = new SubWindow(mMainViewModel); 28 subWindow.Show(); 29 } 30 31 private void OnClickCountUp(object sender, RoutedEventArgs e) 32 { 33 count++; 34 mMainViewModel.CountVal = count.ToString(); 35 36 if (mPoint == null) 37 { 38 mPoint = new ScatterSeries() { MarkerType = MarkerType.Circle}; 39 } 40 41 //var customAxis = new RangeColorAxis { Key = "customColors" }; 42 //customAxis.AddRange(0, 100, OxyColors.Red); 43 //mMainViewModel.ChartList.Axes.Add(customAxis); 44 //この3行のコメントアウトも試しましたが色が変わっていなかったり、グラフの表示すら消えたりしました。 45 46 mPoint.Points.Add(new ScatterPoint(count, count)); 47 } 48 }
C#
1//MainWindow - ViewModel 2 public class MainViewModel : ViewModelBase 3 { 4 private string count; 5 public string CountVal 6 { 7 get { return count; } 8 set 9 { 10 count = value; 11 NotifyPropertyChanged("CountVal"); 12 } 13 14 } 15 16 private PlotModel chartListVal = new PlotModel(); 17 public PlotModel ChartList 18 { 19 get 20 { 21 return chartListVal; 22 } 23 set 24 { 25 chartListVal = value; 26 NotifyPropertyChanged("ChartList"); 27 } 28 } 29 }
Xaml
1//MainWindow - View 2 <Grid> 3 <Button Content="CountUp" HorizontalAlignment="Left" Height="76" Margin="72,57,0,0" VerticalAlignment="Top" Width="135" Click="OnClickCountUp"/> 4 <Label Content="Count : " HorizontalAlignment="Left" Height="28" Margin="254,73,0,0" VerticalAlignment="Top" Width="53"/> 5 <Label Content="{Binding CountVal}" HorizontalAlignment="Left" Height="28" Margin="307,73,0,0" VerticalAlignment="Top" Width="67"/> 6 7 <Button Content="OpenSubWindow" HorizontalAlignment="Left" Height="74" Margin="342,194,0,0" VerticalAlignment="Top" Width="123" Click="OnClicOpenSubWindow"/> 8 </Grid>
C#
1//SubWindow - View 2 <Grid> 3 <oxy:PlotView Model="{Binding ChartList}" /> 4 </Grid> 5 6//SubWindow - Codebehind 7 public partial class SubWindow : Window 8 { 9 public SubWindow(MainViewModel pMainViewModel) 10 { 11 InitializeComponent(); 12 this.DataContext = pMainViewModel; 13 } 14 }
補足情報
なお本番アプリケーションではグラフのデータ数も増え、色もその都度に変えたいので、ビューに静的定義することは難しいです。
ご助言いただけますと幸いです。
回答1件
あなたの回答
tips
プレビュー