OxyPlotを使用して、折れ線グラフを描写するアプリを作成しているのですが、
X軸の項目に文字列を使う方法がわかりません。
今までは、日付をX軸に持ってきていたので、DateTimeAxisを使用すれば簡単に出来ていたのですが、、、
何かいい方法がありましたら、教えていただければ幸いです。
-- 現在
C#
1 class Data 2 { 3 public double ID { get; set; } 4 public DateTime date { get; set; } 5 public string Items { get; set; } 6 public double Value1 { get; set; } 7 public double Value2 { get; set; } 8 }
C#
1 class Test 2 { 3 public ReactiveCollection<Data> Datas { get; } = new ReactiveCollection<Data>(); 4 5 public void GePlots() 6 { 7 // テスト用にデータを入れる 8 for (int i = 0; i < 5; i++) 9 { 10 var item = "XXXX" + i.ToString(); 11 double v1 = 52.0 + i; 12 double v2 = 61.0 + i; 13 int i2 = i + 1; 14 string dt = "2019/01/0" + i2.ToString(); 15 Datas.Add(new Data { ID = i, date = DateTime.Parse(dt), items = lot, Value1 = v1, Value2 = v2 }); 16 } 17 18 19 var plotTest = new PlotModel() 20 { 21 PlotAreaBorderColor = OxyColors.LightGray, 22 TextColor = OxyColors.LightGray 23 }; 24 25 // OxyPlot X軸 26 var axisX = new LinearAxis() 27 { 28 Title = "Time", 29 Position = AxisPosition.Bottom, 30 TickStyle = TickStyle.None, 31 MajorGridlineStyle = LineStyle.Solid, 32 MajorGridlineColor = OxyColors.Gray, 33 StringFormat = "yyyy/MM/dd", 34 Angle = -90 35 }; 36 37 // OxyPlot Y軸 38 var axisY = new LinearAxis() 39 { 40 Title = "Values", 41 Position = AxisPosition.Left, 42 TickStyle = TickStyle.None, 43 MajorGridlineStyle = LineStyle.Solid, 44 MajorGridlineColor = OxyColors.Gray, 45 MinorGridlineStyle = LineStyle.Dot, 46 MinorGridlineColor = OxyColors.Gray 47 }; 48 49 50 plotTest.Series.Add(new LineSeries() 51 { 52 53 Title = "Value1", 54 ItemsSource = Datas, 55 DataFieldX = "date", 56 DataFieldY = "Value1", 57 //MarkerType = MarkerType.Circle, 58 MarkerSize = 3, 59 //MarkerStroke = OxyColors.Red, 60 MarkerStrokeThickness = 1, 61 //MarkerFill = OxyColors.Red, 62 //Color = OxyColors.Red, 63 IsVisible = chkPT201.Value, 64 RenderInLegend = true 65 }); 66 67 plotTest.Series.Add(new LineSeries() 68 { 69 Title = "Value2", 70 ItemsSource = Datas, 71 DataFieldX = "date", 72 DataFieldY = "Value2", 73 //MarkerType = MarkerType.Circle, 74 MarkerSize = 3, 75 //MarkerStroke = OxyColors.Red, 76 MarkerStrokeThickness = 1, 77 MarkerFill = OxyColors.Red, 78 //Color = OxyColors.Red, 79 IsVisible = chkPT201.Value, 80 RenderInLegend = true 81 }); 82 } 83 }
-- 理想
各LineSeriesの DataFieldXに"Items"の項目(XXXX0-4)を表示するのが理想です。
LabelFormatterを使おうと考えましたが案の定できませんでした。。
また、LinearAxis以外の軸も試してみましたが、文字列が許容されていそうなものは見当たりません。
この程度の情報で申し訳ありませんがよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー