每当 ScalesYAt != 0 时,实时图表就会崩溃

问题描述 投票:0回答:1

我将 LiveChartsCore 2.0.0-rc2 与 .SkiaSharpView 和 .SkiaSharpView.WinForms 一起使用(也是相同的 2.0.0-rc2 版本)

我正在尝试创建一个多轴垂直轴图,例如Tutorial graph

为了简化起见,我尝试仅使用蓝线和红线:

 public partial class ViewModelMultiple2 : ObservableObject
   {
       public ViewModelMultiple2()
       {

           var blue = new SKColor(25, 118, 210);
           var red = new SKColor(229, 57, 53);

           Series = new ObservableCollection<ISeries>
               {
                   new LineSeries<double>
                   {
                       LineSmoothness = 1,
                       Name = "tens",
                       Values = new ObservableCollection<double> { 14, 13, 14, 15, 17 },
                       Stroke = new SolidColorPaint(blue, 2),
                       GeometryStroke = new SolidColorPaint(blue, 2),
                       Fill = null,
                       ScalesYAt = 0
                   },
                   new LineSeries<double>
                   {
                       Name = "tens 2",
                       Values = new ObservableCollection<double> { 11, 12, 13, 10, 13 },
                       Stroke = new SolidColorPaint(blue, 2),
                       GeometryStroke = new SolidColorPaint(blue, 2),
                       Fill = null,
                       ScalesYAt = 0
                   },
                   new LineSeries<double>
                   {
                       Name = "hundreds",
                       Values = new ObservableCollection<double> { 533, 586, 425, 579, 518 },
                       Stroke = new SolidColorPaint(red, 2),
                       GeometryStroke = new SolidColorPaint(red, 2),
                       Fill = null,

                     //!!Here it crashes, unless I set it to 0
                       ScalesYAt = 1 
                   },
   
               };

           YAxes = new List<Axis>
           {
               {
                   LabelsPaint = new SolidColorPaint(blue)
               },
               {
                   LabelsPaint = new SolidColorPaint(red),
                   ShowSeparatorLines = false,
                   Position = LiveChartsCore.Measure.AxisPosition.End
               },
           };

       }
       public List<Axis> YAxes { get; set; }
       public ObservableCollection<ISeries> Series { get; set; }

   }

然后我通过单击按钮在 Form1 中调用它(我认为这可能是问题所在):

 public partial class Form1 : Form
   {

       public Form1()
       {
           InitializeComponent();
           this.ClientSize = new System.Drawing.Size(1300, 830);

}

private void Test2_Click(object sender, EventArgs e)
  {

      var viewModelMultiple2 = new ViewModelMultiple2();
      var cartesianchart5 = new CartesianChart
      {
          XAxes = viewModelMultiple2.YAxes,

//!!When this series below is called, I get:

//This exception was originally thrown at this call stack:
//Inner Exception 1:
//IndexOutOfRangeException: Index was outside the bounds of the array.

          Series = viewModelMultiple2.Series,

          Location = new System.Drawing.Point(10, 10),
          Size = new System.Drawing.Size(1100, 700),
          AutoSize = false

      };

      panel1.Controls.Add(cartesianchart5);
}
}

有人知道为什么这可能是一个问题吗?

我能得到的最好结果是红线的 ScalesYAt = 0

Sample working.. altough not correctly

plot axis livecharts x-axis
1个回答
0
投票

找到了,

问题确实出在按钮调用中 基本上 XAxes、YAxes 和 Series 之间是有区别的..

  var cartesianchart4 = new CartesianChart
  {
      YAxes = viewModelMultiple2.YAxes,
      Series = viewModelMultiple2.Series,
      XAxes = viewModelMultiple2.XAxes,

  
  };
© www.soinside.com 2019 - 2024. All rights reserved.