2016-07-22 26 views
1

Good Day everyone。私はXamarin.Formsポータブルアプリケーションを作成しており、OxyPlotを使用してチャートを表示したいと考えています。Xamarin.Forms:OxyPlotの円グラフが表示されません

OxyPlotについてのhereの文書に続いています。しかし、私はまだちょっと混乱します。あなたは私が従ったプロセスを見て、私がしたことが正しいかどうかを確認できますか?これらは私の理解に基づいています。

は、ここに私がやったことだ:最新バージョンへ

  1. 更新Xamarin.Forms NuGetパッケージ。
  2. OxyPlot.Xamarin.Forms NuGetパッケージをポータブルおよびプラットフォーム固有のプロジェクトに追加します。
  3. OxyPlotレンダラを初期化するには、OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init();を追加します。私のMainActivity.csのXamarin.Forms.Forms.Init()の直後
  4. ポータブルアプリケーションプロジェクトでは、このプロットビューをApp.cs.xに追加しました。私のXAMLページで

    public App() 
    { 
        this.MainPage = new ContentPage 
        { 
        Content = new PlotView 
        { 
        Model = new PlotModel { Title = "Hello, Forms!" }, 
        VerticalOptions = LayoutOptions.Fill, 
        HorizontalOptions = LayoutOptions.Fill, 
         }, 
        }; 
    } 
    
  5. 、私はこの名前空間宣言を追加:

のxmlns:オキシ= "CLR名前空間:OxyPlot.Xamarin.Formsを、アセンブリ= OxyPlot.Xamarin.Forms "

  1. これを同じページに追加しました。ここで

    <oxy:PlotView Model="{Binding Model1}" VerticalOptions="Center" HorizontalOptions="Center" /> 
    

    は、その後全体SalesPage.xaml

    <?xml version="1.0" encoding="utf-8" ?> 
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms" 
        xmlns:ViewModels="clr-namespace:XamarinFormsDemo.ViewModels;assembly=XamarinFormsDemo" 
        x:Class="XamarinFormsDemo.Views.SalesPage" 
        BackgroundImage="bg3.jpg" 
        Title="Sales Page"> 
    
    
    
        <ContentPage.BindingContext> 
        <ViewModels:SalesVM/> 
        </ContentPage.BindingContext> 
    
    
        <oxy:PlotView Model="{Binding Model1}" VerticalOptions="Center" HorizontalOptions="Center"/> 
    
    
    </ContentPage> 
    
  2. のコードですが、私は名前の私のチャートの内容が含まれている私の見解モデルを呼び出そうとしましたPiewViewModel.cs

    using OxyPlot; 
    using OxyPlot.Series; 
    
    namespace ExampleLibrary 
    { 
    
        public class PieViewModel 
        { 
         private PlotModel modelP1; 
         public PieViewModel() 
        { 
         modelP1 = new PlotModel { Title = "Pie Sample1" }; 
    
         dynamic seriesP1 = new PieSeries { StrokeThickness = 2.0,  InsideLabelPosition = 0.8, AngleSpan = 360, StartAngle = 0 }; 
    
         seriesP1.Slices.Add(new PieSlice("Africa", 1030) { IsExploded = false, Fill = OxyColors.PaleVioletRed }); 
         seriesP1.Slices.Add(new PieSlice("Americas", 929) { IsExploded = true }); 
         seriesP1.Slices.Add(new PieSlice("Asia", 4157) { IsExploded = true }); 
         seriesP1.Slices.Add(new PieSlice("Europe", 739) { IsExploded = true }); 
         seriesP1.Slices.Add(new PieSlice("Oceania", 35) { IsExploded = true }); 
    
         modelP1.Series.Add(seriesP1); 
    
        } 
    
        public PlotModel Model1 
        { 
         get { return modelP1; } 
         set { modelP1 = value; } 
        } 
        } 
    } 
    
  3. ここは私のMainActivity.cs for Androidです

    using System; 
        using Android.App; 
        using Android.Content.PM; 
        using Android.Runtime; 
        using Android.Views; 
        using Android.Widget; 
        using Android.OS; 
        using ImageCircle.Forms.Plugin.Droid; 
    
        namespace XamarinFormsDemo.Droid 
        { 
         [Activity(Label = "XamarinFormsDemo", Icon = "@drawable/recordsicon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 
         public class MainActivity :   global::Xamarin.Forms.Platform.Android.FormsApplicationActivity 
         { 
          protected override void OnCreate(Bundle bundle) 
    { 
        base.OnCreate(bundle); 
    
        global::Xamarin.Forms.Forms.Init(this, bundle); 
        OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init(); 
        LoadApplication(new App()); 
        ImageCircleRenderer.Init(); 
          } 
         } 
        } 
    

私が間違ったことを教えてもらえますか?グラフは表示されません。私のような初心者への助けは非常に高く評価されます。どうもありがとう。

+0

から派生する必要がありますか?または実行時に作成されたPlotViewのような 'Title =" Hello、Forms! "'があり、関連するPieViewModelバインディングを持つDesign-Time作成PlotViewに 'Title =" Pie Sample1 "が表示されることを期待していますか? –

+0

@JeremyThompson画面には何もありません。 –

+0

あなたの 'public class MainActivity:AndroidActivity'を表示できますか?例えば:https://github.com/oxyplot/documentation-examples/blob/master/HelloWorld/XamarinFormsApp1/XamarinFormsApp1/XamarinFormsApp1.Android/MainActivity.cs –

答えて

1

あなたMainActivityクラスはありませんのでPieGraphが示されていないという結果であるAndroidActivityないFormsApplicationActivity

+0

@JeremyStephens私はそれを交換しましたが、何も起こっていないサー?私のコードをチェックしましたか?私の拘束力は正しいと思いますか?お返事ありがとうございます。 –

+0

デモサンプルとは異なるMainActivityクラスのみが表示されます。なぜサンプルをダウンロードしてそれが動作することを確認するビルドして、それをあなたと比較し、違いを発見してみてください。 –

+0

しかし、それは私がやったことですか?なぜそれが現れないのかわからないのですか? –