2016-04-25 12 views
0

Xamarin Nugetパッケージマネージャのios-charts v2.2.3.0をポートするだけです。xamarin.ios ios-chart BarChartDataSet

public void BarChart(BarChartModel _barChartModel, BarChartView _barChartView, string _fromView, bool animateChart) 
    { 
     try { 
      barChartModel = _barChartModel; 
      barChartView = _barChartView; 

      barChartView.SetDrawBarShadowEnabled (false); 
      barChartView.SetMaxVisibleValueCount (15); 
      barChartView.SetPinchZoomEnabled (true); 
      barChartView.SetDrawGridBackgroundEnabled (false); 
      barChartView.ScaleYEnabled = false; 

      // Chart axis' layout configurations 
      ChartXAxis xAxis = barChartView.XAxis; 
      xAxis.SetLabelPosition (XAxisLabelPosition.Bottom); 
      xAxis.SetDrawGridLinesEnabled (false); 
      xAxis.SetLabelTextColor (chartTextColor); 
      xAxis.SpaceBetweenLabels = 2; 
      xAxis.SetAvoidFirstLastClippingEnabled (true); 
      xAxis.SetLabelWidth (30f); 

      ChartYAxis leftAxis = barChartView.LeftAxis; 
      leftAxis.SetLabelCount (10, false); 
      leftAxis.SetLabelPosition (YAxisLabelPosition.OutsideChart); 
      leftAxis.SpaceTop = 10f; 
      leftAxis.SetLabelTextColor (chartTextColor); 
      leftAxis.ValueFormatter = new NSNumberFormatter(); 

      ChartYAxis rightAxis = barChartView.RightAxis; 
      rightAxis.SetDrawGridLinesEnabled (false); 
      rightAxis.SetDrawLabelsEnabled (false); 

      ChartLegend legend = barChartView.Legend; 
      legend.SetPosition (ChartLegendPosition.BelowChartCenter); 
      legend.SetForm (ChartLegendForm.Square); 
      legend.FormSize = 9f; 
      legend.SetFormToTextSpace (11f); 
      legend.XEntrySpace = 15f; 
      legend.TextColor = chartTextColor; 

      // X Axis 
      // -- directly get from dataModel.xAxis; 
      NSObject[] truncatedXAxis = new NSObject[barChartModel.xAxis.Count]; 
      for (int t = 0; t < barChartModel.xAxis.Count; t++) { 
       if (barChartModel.xAxis [t].Length > 13) 
        truncatedXAxis [t] = NSObject.FromObject (barChartModel.xAxis [t].Substring (0, 11) + ".."); 
       else 
        truncatedXAxis [t] = NSObject.FromObject (barChartModel.xAxis [t]); 
      } 

      // Y Axis 
      BarChartDataSet[] yDataSets = new BarChartDataSet[barChartModel.yAxis.Count]; 

      for (int i = 0; i < barChartModel.yAxis.Count; i++) { 
       ChartDataEntry[] barEntry = new ChartDataEntry[barChartModel.yAxis [i].Count]; 
       //List<ChartDataEntry> dataEntryList = new List<ChartDataEntry>(); 
       for (int j = 0; j < barChartModel.yAxis [i].Count; j++) { 
        barEntry[j] = new ChartDataEntry((float)barChartModel.yAxis [i] [j], j); 
        //dataEntryList.Add(new ChartDataEntry((float)barChartModel.yAxis [i] [j], j)); 
       } 

       //BarChartDataSet yDataSet = new BarChartDataSet (dataEntryList.ToArray(), barChartModel.dataSetLegend [i].ToString()); 
       // Crashes HERE V 
       BarChartDataSet yDataSet = new BarChartDataSet (barEntry, barChartModel.dataSetLegend [i].ToString()); 
       yDataSet.SetColor(chartColors [i]); 

       yDataSets[i] = yDataSet; 
      } 

      // Combine xAxis & yAxis 
      BarChartData data = new BarChartData (truncatedXAxis, yDataSets); 
      data.SetValueTextColor (chartTextColor); 
      data.SetHighlightEnabled (false);   // Disable highlight selection 

      barChartView.SetData(data); 
      barChartView.SetNoDataTextDescription (""); 
      barChartView.SetDescriptionText (""); // Disable description - barChartData.SetDescription (String.IsNullOrEmpty (dataModel.name) ? "" : dataModel.name); 
      barChartView.SetNoDataText (""); // Text displayed when no data is given ("You need to provide data for the chart."); 
      if (animateChart) 
       barChartView.AnimateWithYAxisDuration (800); 
     } catch (Exception ex) { 
      LogHelper.Debug ("iOSChartHelper", ex.Message, ex); 
     } 
    } 

バインディング・フレームワークからのエラーメッセージスロー以下でクラッシュしたところ、このコメント// Crashes HERE V以下の行があります。

fatal error: NSArray element failed to match the Swift Array Element type

BarchartDataSetを別の変数に変更しましたが運が変更されました。 誰かがこの問題についてサンプルコードまたは解決策を持っていますか?

答えて

1

barEntry配列は、ChartDataEntry配列です。 BarChartDataEntryの配列を使用する必要があります。

BarChartDataEntry[] barEntry = new BarChartDataEntry[someIntValue]; 
関連する問題