wpf OxyPlot AreaSeries无法水平工作

oxalkeyp  于 2023-03-19  发布在  其他
关注(0)|答案(2)|浏览(191)

我使用OxyPlot中的AreaSeries来绘制垂直AreaSeries
我应用了一个从不同颜色的AreaSeries列表构建的方法。

private static void AddTriggerAreaSeries(PlotModel plotModel, int initialPoint, int endingPoint, int index)
        {
            var seriesArea = new AreaSeries();

            seriesArea.Title = "Instruction";
            seriesArea.Color = OxyColors.Transparent;
            seriesArea.Fill = TriggerColorList[index];

            //Draws vertically from bottom to top (0 -> 20)  
            //j referes to the second axis, the y axis in this case (vertical axis)     
            //The initial and ending points represent interval limits in which the area series is drawn

            for (var j = 0; j < 20; j++)
            {
                seriesArea.Points.Add(new DataPoint(initalPoint, j));
            }
            for (var j = 0; j < 20; j++)
            {
                seriesArea.Points.Add(new DataPoint(endingPoint, j));
            }
            plotModel.Series.Add(seriesArea);
        }

参见下图

这段代码适用于vertical series。但是,当我试图水平绘制同样的东西时,它不会从我给予的区间开始绘制。
下面是我用来绘制AreaSeries horizontally的代码示例:

// Basically same code that I used but calling seriesArea.Points.Add(new DataPoint(x, y)) reversed, such that the line goes in the x direction
        for (var j = 0; j < 20; j++)
        {
            seriesArea.Points.Add(new DataPoint(j, initalPoint));
        }
        for (var j = 0; j < 20; j++)
        {
            seriesArea.Points.Add(new DataPoint(j, endingPoint));
        }
        plotModel.Series.Add(seriesArea);

下面是这段代码的结果图在这个例子中initialPoint=1endingPoint=2 .我试着画interval [1,2],而不是只画从interval [0,1]和结束点只画一条线:

8nuwlpux

8nuwlpux1#

我更改了打印的方向,使AreaSeries垂直。
以下是它最终的样子:下面是代码:(我使用MVVM模式,我在一个类中创建一个PlotModel,然后对其应用方法)

private static void CreateColorBar(PlotModel plotModel, HemodynamicsMapping hemodynamicsMapping)
        {
            plotModel.InvalidatePlot(false);

            plotModel.Series.Clear();
            plotModel.Axes.Clear();

            // x axis
            plotModel.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Right,
                AbsoluteMaximum = 10,
                Minimum = 0,
                AbsoluteMinimum = 0,
                Maximum = 10,
                MajorTickSize = 0,
                MinorTickSize = 0,
                TextColor = OxyColors.Transparent
            });

            // y axis 
            plotModel.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Bottom,
                AbsoluteMaximum = 61,
                AbsoluteMinimum = 0,
                Maximum = 61,
                Minimum = 0,
                MajorTickSize = 0,
                MinorTickSize = 0,
                TextColor = OxyColors.Transparent
            });

            // z axis 
            // I only use this axis to show the labels you see in the picture
            plotModel.Axes.Add(new CategoryAxis
            {
                Position = AxisPosition.Bottom,
                AbsoluteMaximum = 8,
                AbsoluteMinimum = 0,
                Maximum = 8,
                Minimum = 0,
                MajorTickSize = 0,
                MinorTickSize = 0
            });

            var count = 0;
            //Adds series with colors form black to green
            for (var i = 3; i > 0; i--)
            {
                for (var j = 9; j >= 0; j--)
                {
                    AddColorBarArea(plotModel, i, j, hemodynamicsMapping, count, -1);
                    count++;
                }
            }

            //Adds green series 
            AddColorBarArea(plotModel, 1, 0, hemodynamicsMapping, count, 1);

            //Adds series with colors form green to white
            for (var i = 1; i < 5; i++)
            {
                for (var j = 0; j < 10; j++)
                {
                    AddColorBarArea(plotModel, i, j, hemodynamicsMapping, count, 1);
                    count++;
                }
            }

            plotModel.InvalidatePlot(true);
        }

        // Adds a series to the plot. There are 61 series since there are 61 colors.
        private static void AddColorBarArea(PlotModel plotModel,int i, int j, HemodynamicsMapping hemodynamicsMapping, int count, int negative)
        {
            var seriesArea = new AreaSeries();

            for (var k = 0; k < 500; k++)
            {
                seriesArea.Points.Add(new DataPoint(count, k));
            }
            for (var k = 0; k < 500; k++)
            {
                seriesArea.Points.Add(new DataPoint(count + 1, k));
            }

            seriesArea.Color = hemodynamicsMapping.ChannelColor(j, i, negative).ToOxyColor();
            seriesArea.Fill = hemodynamicsMapping.ChannelColor(j, i, negative).ToOxyColor();

            plotModel.Series.Add(seriesArea);
        }

然而,这个颜色条的理想位置应该是垂直的,因为我正在特灵实现这样的东西:(此处为图片)

aurhwmvo

aurhwmvo2#

根据AreaSeries documentation
AreaSeries显示两组点之间或一组点与基线之间的区域。
我不得不承认,这并不是很重要,但它确实表明有两组点。Points属性是一组,Points2是另一组。您应该同时使用它们(除非您打算使用基线)。此外,除非您希望区域不是矩形,否则我相信您只需要为每组设置两个点,如下所示(注意:我没有测试它,但它与我测试过的代码类似):

seriesArea.Points.Add(new DataPoint(0, initialPoint));
 seriesArea.Points.Add(new DataPoint(19, initialPoint));
 seriesArea.Points2.Add(new DataPoint(0, endPoint));
 seriesArea.Points2.Add(new DataPoint(19, endPoint));
 
 plotModel.Series.Add(seriesArea);

此外,如果AreaSeries仍然不适用,可以尝试RectangleAnnotationPolygonAnnotation
注意:在撰写本文时,除了RectangleAnnotaionPolygonAnnotation存在这一事实之外,还没有任何关于它们的文档。

相关问题