2013-04-26 2 views
0

Привет, ребята, у меня проблема с основным сюжетом в xamarin. Мне удалось создать диаграмму, как показано ниже:xamarin core plot значение оси y

click here for the graph

Я использую этот код:

/// <summary> 
    /// Configure the Axes of the graph 
    /// </summary> 
    void SetupAxes() 
    { 
     var plotspace = _graph.DefaultPlotSpace; 
     plotspace.AllowsUserInteraction = true; 

     var axisSet = (CPTXYAxisSet)_graph.AxisSet; 

     // Label x with a fixed interval policy 
     var x = axisSet.XAxis; 
     x.LabelingPolicy = CPTAxisLabelingPolicy.None; 
     x.Title = "X Axis"; 
     x.TitleOffset = 0; 
     x.MinorTickLength = 5f; 
     x.MajorTickLength = 7f; 
     x.LabelOffset = 3; 
     x.MajorIntervalLength = 5; 
     x.MinorTicksPerInterval = 4; 



     // Label y with an automatic label policy. 
     var y = axisSet.YAxis; 
     y.LabelingPolicy = CPTAxisLabelingPolicy.None; 
     y.LabelOffset = 0; 
     y.Title = "Y Axis"; 
     y.TitleOffset = 0; 
     y.MinorTickLength = 5f; 
     y.MajorTickLength = 7f; 
     y.LabelOffset = 3; 
     y.MajorIntervalLength = 5; 
     y.MinorTicksPerInterval = 4; 
    } 

    /// <summary> 
    /// Set up data source and configure plots 
    /// </summary> 
    void SetupBarPlots(List<float> inputSocket) 
    { 

     var barPlot = new CPTBarPlot 
     { 
      DataSource = new BarSourceData(inputSocket), 
      BaseValue = 0, 
      BarOffset = (NSDecimal)(-0.25), 
      Identifier = (NSString)"Bar Plot 1" 
     }; 

     _graph.AddPlot(barPlot); 

     barPlot.Fill = new CPTFill(CPTColor.BrownColor); 
     _graph.AddPlot(barPlot, _graph.DefaultPlotSpace); 

     var space = _graph.DefaultPlotSpace as CPTXYPlotSpace; 
     space.ScaleToFitPlots(new CPTPlot[] { barPlot }); 

     //get the highest value in the input data 
     var yMax = (decimal)inputSocket.Max(); 
     decimal newYMax = yMax*2;    
     space.YRange = new CPTPlotRange(-20, new NSDecimalNumber(newYMax.ToString()).NSDecimalValue); 

     decimal newXMax = (decimal)space.XRange.MaxLimit + 2; 
     decimal newXMin = (decimal)space.XRange.MinLimit - 1; 
     space.XRange = new CPTPlotRange(new NSDecimalNumber(newXMin.ToString()).NSDecimalValue, 
             new NSDecimalNumber(newXMax.ToString()).NSDecimalValue); 

     //RectangleF(position x, position y, width, height 
     //AddSubview = adding a view on top of a View 
     _view.AddSubview(new CPTGraphHostingView(new RectangleF(20, 320, 662, 320)) 
     { 
      HostedGraph = _graph 
     }); 
    } 

Я хочу, чтобы показать значение у в графе (красный квадрат в image), так что может выглядеть как правильный граф. У кого-нибудь есть опыт создания графика с использованием Xamarin/monotouch? Существует не так много учебника по xamarin для основного сюжета. Спасибо до этого:

ответ

0

Оказывается, мне нужно настроить labellingPolicy на Automatic. См. Ниже:

y.LabelingPolicy = CPTAxisLabelingPolicy.Automatic; 

Затем оно задает значение оси y на основе данных.