【问题标题】:OxyPlot Zero LineOxyPlot 零线
【发布时间】:2014-11-26 17:52:55
【问题描述】:

我们有一个带有正负值的简单 ColumnChart。

虽然在 0 线处,但图表上没有线。我们如何启用零线跨越?

见附图

【问题讨论】:

    标签: charts xamarin xamarin.forms oxyplot


    【解决方案1】:

    假设您使用 LinearAxis 作为 Y 轴。

    您需要做的就是添加到您的 LinearAxis。

    plotModel.Axes.Add(new LinearAxis()
            {
                Title = "Percentage",
                Position = AxisPosition.Left,
                // Magic Happens here we add the extra grid line on our Y Axis at zero
                ExtraGridlines = new Double[] { 0 }
            });
    

    【讨论】:

      【解决方案2】:

      看看这对我来说在 Android 上是否有效尚未在 IOS 上测试过:

      public static PlotModel Withnegativevalues()
      {
          var plotModel1 = new PlotModel();
          plotModel1.LegendBorderThickness = 0;
          plotModel1.LegendOrientation = LegendOrientation.Horizontal;
          plotModel1.LegendPlacement = LegendPlacement.Outside;
          plotModel1.LegendPosition = LegendPosition.BottomCenter;
          plotModel1.Title = "With negative values";
          var categoryAxis1 = new CategoryAxis();
          categoryAxis1.MinorStep = 1;
          categoryAxis1.Labels.Add("Category A");
          categoryAxis1.Labels.Add("Category B");
          categoryAxis1.Labels.Add("Category C");
          categoryAxis1.Labels.Add("Category D");
          categoryAxis1.ActualLabels.Add("Category A");
          categoryAxis1.ActualLabels.Add("Category B");
          categoryAxis1.ActualLabels.Add("Category C");
          categoryAxis1.ActualLabels.Add("Category D");
          plotModel1.Axes.Add(categoryAxis1);
          var linearAxis1 = new LinearAxis();
          linearAxis1.MaximumPadding = 0.06;
          linearAxis1.MinimumPadding = 0.06;
          linearAxis1.ExtraGridlines = new Double[1];
          linearAxis1.ExtraGridlines[0] = 0;
          plotModel1.Axes.Add(linearAxis1);
          var columnSeries1 = new ColumnSeries();
          columnSeries1.StrokeThickness = 1;
          columnSeries1.Title = "Series 1";
          columnSeries1.Items.Add(new ColumnItem(25,-1,"OxyColors.Automatic"));
          columnSeries1.Items.Add(new ColumnItem(137,-1,"OxyColors.Automatic"));
          columnSeries1.Items.Add(new ColumnItem(18,-1,"OxyColors.Automatic"));
          columnSeries1.Items.Add(new ColumnItem(40,-1,"OxyColors.Automatic"));
          plotModel1.Series.Add(columnSeries1);
          var columnSeries2 = new ColumnSeries();
          columnSeries2.StrokeThickness = 1;
          columnSeries2.Title = "Series 2";
          columnSeries2.Items.Add(new ColumnItem(-12,-1,"OxyColors.Automatic"));
          columnSeries2.Items.Add(new ColumnItem(-14,-1,"OxyColors.Automatic"));
          columnSeries2.Items.Add(new ColumnItem(-120,-1,"OxyColors.Automatic"));
          columnSeries2.Items.Add(new ColumnItem(-26,-1,"OxyColors.Automatic"));
          plotModel1.Series.Add(columnSeries2);
          var columnSeries3 = new ColumnSeries();
          columnSeries3.StrokeThickness = 1;
          columnSeries3.Title = "Series 3";
          columnSeries3.Items.Add(new ColumnItem(21,-1,"OxyColors.Automatic"));
          columnSeries3.Items.Add(new ColumnItem(8,-1,"OxyColors.Automatic"));
          columnSeries3.Items.Add(new ColumnItem(48,-1,"OxyColors.Automatic"));
          columnSeries3.Items.Add(new ColumnItem(3,-1,"OxyColors.Automatic"));
          plotModel1.Series.Add(columnSeries3);
          var columnSeries4 = new ColumnSeries();
          columnSeries4.StrokeThickness = 1;
          columnSeries4.Title = "Series 4";
          columnSeries4.Items.Add(new ColumnItem(-8,-1,"OxyColors.Automatic"));
          columnSeries4.Items.Add(new ColumnItem(-21,-1,"OxyColors.Automatic"));
          columnSeries4.Items.Add(new ColumnItem(-3,-1,"OxyColors.Automatic"));
          columnSeries4.Items.Add(new ColumnItem(-48,-1,"OxyColors.Automatic"));
          plotModel1.Series.Add(columnSeries4);
          return plotModel1;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-23
        • 2021-02-20
        • 1970-01-01
        相关资源
        最近更新 更多