2017-08-30 8 views
0

OxyPlotビューを使用して、ダイアグラムにデータを表示しています。昨日まで正しく動作しています。バープロットを含むモデルを作成中のOxyplot例外

Oxyplotのexcepttion:オブジェクト参照のインスタンスに設定されていない私は、アクティビティページがOxyPlotを含んで開くたびに、それだけでモバイル画面上にこのメッセージを示し、自分のアプリケーションにデータベース部(SQLiteの)を添加し、以来 オブジェクトです。型system.NullReferenceExceptionの例外は私がSystem.NullReferenceExceptionがスローされたときにブレークポイントを置くことによって、それが起こっている場所を見つけることを試みた[0x00006]

Oxyplot.ReflectionPath..ctor(可能System.Stringパス)で を投げたが、プログラムは停止されませんでした。 UPDATED

design d = new design(); 

var plotView = new PlotView(this); 

plotView.Model = d.CreatePlotModelTest; 
this.AddContentView(plotView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)); 

私が気づい

、代わりにバーシリーズのプロットモデルを作成しながら、私は線形シリーズを使用した場合、エラーの私の活動のユーザインタフェースにPlotViewコントロールを追加する

消えるだろう。しかし、私が棒のシリーズを試してみると(下のコードでは、あなたがコメントされているのを見ることができます)、アプリケーションは私にエラーを再度表示します。

public PlotModel CreatePlotModelTest() 
    { 
     var plotModel = new PlotModel { Title = "OxyPlot Demo" }; 

     plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); 
     plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Maximum = 10, Minimum = 0 }); 


     var series1 = new LineSeries 
     { 
      MarkerType = MarkerType.Circle, 
      MarkerSize = 4, 
      MarkerStroke = OxyColors.White 
     }; 

     series1.Points.Add(new DataPoint(0.0, 6.0)); 
     series1.Points.Add(new DataPoint(1.4, 2.1)); 
     series1.Points.Add(new DataPoint(2.0, 4.2)); 
     series1.Points.Add(new DataPoint(3.3, 2.3)); 
     series1.Points.Add(new DataPoint(4.7, 7.4)); 
     series1.Points.Add(new DataPoint(6.0, 6.2)); 
     series1.Points.Add(new DataPoint(8.9, 8.9)); 

     plotModel.Series.Add(series1); 

     /*var barSeries = new BarSeries 
     { 
      ItemsSource = new List<BarItem>(new[] 
    { 
      new BarItem{ Value = (2) }, 
      new BarItem{ Value = (3) }, 
      new BarItem{ Value = (4) }, 
      new BarItem{ Value = (5) }, 
      new BarItem{ Value = (6) } 
    }), 
      LabelPlacement = LabelPlacement.Inside, 
      LabelFormatString = "{2:0.0}" 
     }; 
     plotModel.Series.Add(barSeries); 

     plotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom }); 
      plotModel.Axes.Add(new CategoryAxis 
      { 
       Position = AxisPosition.Left, 
       Key = "CakeAxis", 
       ItemsSource = new[] 
        { 
      "Apple cake", 
      "Baumkuchen", 
      "Bundt Cake", 
      "Chocolate cake", 
      "Carrot cake" 
    } 
      });*/ 

     return plotModel; 
    } 

誰かが、バーシリーズのモデルを作成する際の問題点は何ですか?

+1

どのラインでエラーが発生していますか? – Piyush

+0

これは私の問題です。私はブレークポイントを設定しましたが、実際にVSはエラーをどのラインで表示していません。 –

+0

'energyBarsList'と' PlotView'とは何ですか?あなたが作成したPlotViewクラスを表示します。 – Piyush

答えて

0

更新日:

私はこのようなplotModelを作成する記述する場合には、それがうまく機能:

public PlotModel CreatePlotModelTest() 
    { 
     var model = new PlotModel 
     { 
      Title = "BarSeries", 
      LegendPlacement = LegendPlacement.Outside, 
      LegendPosition = LegendPosition.BottomCenter, 
      LegendOrientation = LegendOrientation.Horizontal, 
      LegendBorderThickness = 0 
     }; 


     var rand = new Random(); 
     double[] cakePopularity = new double[5]; 
     for (int i = 0; i < 5; ++i) 
     { 
      cakePopularity[i] = rand.NextDouble(); 
     } 
     var sum = cakePopularity.Sum(); 

     var s2 = new BarSeries { Title = "Series 1", StrokeColor = OxyColors.Black, StrokeThickness = 1 }; 
     s2.Items.Add(new BarItem { Value = (cakePopularity[0]/sum * 100) }); 
     s2.Items.Add(new BarItem { Value = (cakePopularity[1]/sum * 100) }); 
     s2.Items.Add(new BarItem { Value = (cakePopularity[2]/sum * 100) }); 
     s2.Items.Add(new BarItem { Value = (cakePopularity[3]/sum * 100) }); 
     s2.Items.Add(new BarItem { Value = (cakePopularity[4]/sum * 100) }); 

     var categoryAxis = new CategoryAxis { Position = AxisPosition.Left }; 
     categoryAxis.Labels.Add("Apple cake"); 
     categoryAxis.Labels.Add("Baumkuchen"); 
     categoryAxis.Labels.Add("Bundt Cake"); 
     categoryAxis.Labels.Add("Chocolate cake"); 
     categoryAxis.Labels.Add("Carrot cake"); 
     var valueAxis = new LinearAxis { Position = AxisPosition.Bottom, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0 }; 
     model.Series.Add(s2); 
     //model.Series.Add(s2); 
     model.Axes.Add(categoryAxis); 
     model.Axes.Add(valueAxis); 

     return model; 
    } 
0

例外は、この行によって引き起こされる。このよう

LabelFormatString = "{2:0.0}", 

を無効に。私はあなたがこれを探していると信じています:

LabelFormatString = "{#:0.0}", 
関連する問題