【问题标题】:Adding MarkerStroke color adds thick lines when Smooth is true当 Smooth 为 true 时,添加 MarkerStroke 颜色会添加粗线
【发布时间】:2017-08-01 18:58:15
【问题描述】:

我在 Xamarin 表单 中使用OxyPlot 关注AreaSeries 图表。它有三个系列。

  1. Smooth = true,MarkerStroke = 默认,结果符合预期
  2. Smooth = true,MarkerStroke = Yellow,粗线出现在线条上方
  3. Smooth = false,MarkerStroke = Yellow,结果符合预期

因此,当我使用 Smooth = true 并为 MarkerStroke 定义颜色时,它会添加一条不需要的粗线。如何修复/解决它?

注意:在 Line Series 中,它按预期工作。问题仅在区域系列上。

绘图模型

public class MyOxyPlotModelData
{
        public PlotModel AreaModel { get; set; }

        public MyOxyPlotModelData()
        {
             AreaModel = CreateAreaChart();

        }

        public PlotModel CreateAreaChart()
        {
            PlotModel plotModel1 = new PlotModel { Title = "Area" };
            var valueAxisX = new LinearAxis
            {
                Position = AxisPosition.Bottom,
                AxislineColor = OxyColors.White,
                TicklineColor = OxyColors.White,
                TextColor = OxyColors.White,
                FontSize = 12,
                IsZoomEnabled = false,
                IsPanEnabled = false
            };

            var valueAxisY = new LinearAxis
            {
                Position = AxisPosition.Left,
                //Maximum = 15,
                //Minimum = 0,
                AxislineColor = OxyColors.White,
                TicklineColor = OxyColors.White,
                TextColor = OxyColors.White,
                FontSize = 12,
                IsZoomEnabled = false,
                IsPanEnabled = false
            };

            plotModel1.Axes.Add(valueAxisX);
            plotModel1.Axes.Add(valueAxisY);

            plotModel1.DefaultColors = new List<OxyColor>
            {
                OxyColors.Purple,
                OxyColors.DeepPink,
                OxyColors.Teal 
                //OxyColor.FromRgb(0x20, 0x4A, 0x87)
            };

            AreaSeries areaSeries1 = new AreaSeries
            {
                MarkerType = MarkerType.Circle,
                MarkerSize = 2,
                //MarkerStroke = OxyColors.White,
                StrokeThickness = 1,
                Smooth = true
            };
            areaSeries1.Points.Add(new DataPoint(0, 50));
            areaSeries1.Points.Add(new DataPoint(10, 140));
            areaSeries1.Points.Add(new DataPoint(20, 80));


            AreaSeries areaSeries2 = new AreaSeries
            {
                MarkerType = MarkerType.Circle,
                MarkerSize = 2,
                MarkerStroke = OxyColors.Yellow,
                StrokeThickness = 1,
                Smooth = true
            };
            areaSeries2.Points.Add(new DataPoint(0, 30));
            areaSeries2.Points.Add(new DataPoint(15, 150));
            areaSeries2.Points.Add(new DataPoint(20, 20));


            AreaSeries areaSeries3 = new AreaSeries
            {
                MarkerType = MarkerType.Circle,
                MarkerSize = 2,
                MarkerStroke = OxyColors.Yellow,
                StrokeThickness = 1,
                Smooth = false
            };
            areaSeries3.Points.Add(new DataPoint(0, 40));
            areaSeries3.Points.Add(new DataPoint(15, 110));
            areaSeries3.Points.Add(new DataPoint(20, 55));

            plotModel1.Series.Add(areaSeries1);
            plotModel1.Series.Add(areaSeries2);
            plotModel1.Series.Add(areaSeries3);


            return plotModel1;

        }
}

应用程序。 XAML.cs

public App()
    {
        InitializeComponent();
        var vSampleData = new MyOxyPlotModelData();

        MainPage = new OxyPlotNewSeries.MainPage { BindingContext = vSampleData };

    }

MainPage.XAML

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:OxyPlotNewSeries"
             xmlns:oxy="clr-namespace:OxyPlot.Xamarin.Forms;assembly=OxyPlot.Xamarin.Forms" 
             x:Class="OxyPlotNewSeries.MainPage">

    <AbsoluteLayout>

        <oxy:PlotView Model="{Binding AreaModel}" BackgroundColor="#000000"
                  AbsoluteLayout.LayoutBounds="10,30,.9,.9"
                  AbsoluteLayout.LayoutFlags="WidthProportional,HeightProportional" />
    </AbsoluteLayout>

</ContentPage>

【问题讨论】:

  • 平滑会产生很多中间点。当您定义一个标记时,它会在所有这些点上绘制一个标记。粗线只是靠近在一起的标记。您可以通过不添加标记来绕过它。
  • 就像@PalleDue 指出的那样,如果你不想要它,就不要使用它。虽然如果你不喜欢厚度,我看不到 MarkerStrokeThickness 属性设置在任何地方?
  • @PalleDue 为什么它在线条系列中工作正常而不是在区域系列中?请看问题中的截图
  • 你的意思是为什么区域底部有一行?要不然是啥?区域将绘制一个带有点曲线的路径形状,线条只是一条带有点曲线的线,因此它没有像形状那样的边框笔触。
  • @ChrisW。在该行中,有六个标记笔划仅显示为白色圆圈(因为原始数据集中有六个条目)。但是在面积图中,我没有看到原始数据集中存在的三个数据点。我所看到的只是一条厚厚的黄色曲线。我想在区域系列上看到 3 个黄色圆圈。

标签: c# xaml xamarin xamarin.forms oxyplot


【解决方案1】:

您的一个选择是改用TwoColorAreaSeries,因为您所描述的问题不会发生在此系列类型中。

TwoColorAreaSeries areaSeries2 = new TwoColorAreaSeries
{
    MarkerType = MarkerType.Circle,
    MarkerSize = 5,
    MarkerStroke = OxyColors.Yellow,
    MarkerStrokeThickness = 5,
    StrokeThickness = 1,
    Smooth = true
};
areaSeries2.Points.Add(new DataPoint(0, 30));
areaSeries2.Points.Add(new DataPoint(15, 140));
areaSeries2.Points.Add(new DataPoint(20, 20));

编辑:这是一个错误吗?可能是......虽然从他们自己的例子来看,它似乎是为了绘制这样的东西:

还有这个:

【讨论】:

  • 那么,这是AreaSeries中的错误吗?
  • 请看我的编辑
猜你喜欢
  • 2022-11-12
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
相关资源
最近更新 更多