1

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

尽管在 0 线处,但图表上没有线。我们如何启用零线?

见附图

在此处输入图像描述

4

2 回答 2

6

假设您使用 LinearAxis 作为 Y 轴。

您需要做的就是添加到您的线性轴。

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 }
        });
于 2015-02-11T02:32:03.197 回答
-1

看看这适用于我在 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;
}
于 2014-11-27T14:17:12.067 回答