Graph xamarin岩芯图y轴值

Graph xamarin岩芯图y轴值,graph,xamarin.ios,core-plot,Graph,Xamarin.ios,Core Plot,大家好,我对xamarin的核心情节有问题。我成功地创建了一个如下图: 我正在使用以下代码: /// <summary> /// Configure the Axes of the graph /// </summary> void SetupAxes() { var plotspace = _graph.DefaultPlotSpace; plotspace.AllowsUserInteraction =

大家好,我对xamarin的核心情节有问题。我成功地创建了一个如下图:

我正在使用以下代码:

/// <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
        });
    }
//
///配置图形的轴
/// 
void SetupAxes()
{
var plotspace=\u graph.DefaultPlotSpace;
plotspace.allowUserInteraction=true;
var axisSet=(CPTXYAxisSet)\u graph.axisSet;
//使用固定间隔策略标记x
var x=axisSet.XAxis;
x、 LabelingPolicy=CPTAxisLabelingPolicy.None;
x、 Title=“x轴”;
x、 TitleOffset=0;
x、 MinorTickLength=5f;
x、 MajorTickLength=7f;
x、 LabelOffset=3;
x、 主要间隔长度=5;
x、 MinorTicksPerInterval=4;
//使用自动标签策略标记y。
var y=axisSet.YAxis;
y、 LabelingPolicy=CPTAxisLabelingPolicy.None;
y、 LabelOffset=0;
y、 Title=“y轴”;
y、 TitleOffset=0;
y、 MinorTickLength=5f;
y、 MajorTickLength=7f;
y、 LabelOffset=3;
y、 主要间隔长度=5;
y、 MinorTicksPerInterval=4;
}
/// 
///设置数据源并配置绘图
/// 
无效SetupBarPlots(列表inputSocket)
{
var barPlot=新的CPTBarPlot
{
DataSource=新的BarSourceData(inputSocket),
BaseValue=0,
BarOffset=(NSDecimal)(-0.25),
标识符=(NSString)“条形图1”
};
_图.添加图(条形图);
barPlot.Fill=新的CPTFill(CPTColor.BrownColor);
_graph.AddPlot(条形图,_graph.DefaultPlotSpace);
变量空间=_graph.DefaultPlotSpace作为CPTXYPlotSpace;
space.ScaleToFitPlots(新的CPTPlot[]{barPlot});
//获取输入数据中的最高值
var yMax=(十进制)inputSocket.Max();
十进制newYMax=yMax*2;
space.YRange=new CPTPlotRange(-20,new NSDecimalNumber(newYMax.ToString()).NSDecimalValue);
十进制newXMax=(十进制)space.XRange.MaxLimit+2;
decimal newXMin=(decimal)space.XRange.MinLimit-1;
space.XRange=new CPTPlotRange(new NSDecimalNumber(newXMin.ToString()).NSDecimalValue,
新的NSDecimalNumber(newXMax.ToString()).NSDecimalValue);
//矩形F(位置x、位置y、宽度、高度
//AddSubview=在视图顶部添加视图
_视图.添加子视图(新的CPTGraphHostingView(新的矩形F(20,320,662,320))
{
HostedGraph=_图
});
}

我想在图中显示y值(图中的红色方块),使其看起来像一个合适的图。任何人都有使用Xamarin/monotouch创建图的经验吗?核心图的Xamarin教程不多。谢谢:)

结果我必须将LabelingPolicy设置为自动。见下文:

y.LabelingPolicy = CPTAxisLabelingPolicy.Automatic;
然后,它将根据数据设置y轴值