OxyPlot AreaSeries不能水平工作

时间:2016-05-19 10:10:23

标签: wpf plot series oxyplot

我使用AreaSeries中的OxyPlot来绘制垂直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);
        }

见下面Verical area series

的图片

该代码适用于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]绘制,而结束点只绘制一条线:

enter image description here

1 个答案:

答案 0 :(得分:3)

我更改了绘图的方向并使AreaSeries垂直。

以下是它最终的表现: Horizontal bar 这是代码: (我使用MVVM模式,我使用类创建一个PlotModel而不是应用mothods)

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);
        }

然而,这个颜色条的理想位置应该是垂直的,因为我想要实现这样的事情: (这里图片)

enter image description here