【问题标题】:OxyPlot AreaSeries does not work horizontallyOxyPlot AreaSeries 不能水平工作
【发布时间】:2016-05-19 10:10:23
【问题描述】:

我使用来自OxyPlotAreaSeries 绘制垂直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] 绘制,而终点仅绘制一条线:

【问题讨论】:

    标签: wpf plot series oxyplot


    【解决方案1】:

    我改变了绘图的方向并使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);
            }
    

    然而,这个颜色条的理想位置应该是垂直的,因为我正在努力实现这样的目标: (这里是图片)

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多