2016-05-19 5 views
3

Ich verwende AreaSeries von OxyPlot, um vertikale AreaSeries zu zeichnen.OxyPlot AreaSeries funktioniert nicht horizontal

Ich wenden eine Methode an, die aus einer Liste anderer Farbe AreaSeries erstellt. Hier ist der Code:

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

siehe Bild unten Verical area series

Der Code für vertical series arbeitet. Wenn ich jedoch versuche, das gleiche horizontal zu zeichnen, wird es nicht aus einem Intervall, das ich gebe, plotten. Hier

ist ein Beispiel für den Code I plotten verwenden, um die 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); 

Hier ist ein Bild über das Ergebnis dieses Codes In diesem Beispiel wird die initialPoint=1 und endingPoint=2. Ich versuche, die interval [1,2] zu ziehen, statt nur zieht aus interval [0,1] und für den Endpunkt zieht nur eine Zeile:

enter image description here

Antwort

2

ich die Orientierung des Grundstücks geändert und machte die AreaSeries vertikal. Hier

ist, wie es am Ende aussieht: Horizontal bar Hier ist der Code: (ich verwende MVVM Muster, erstelle ich eine PlotModel eine Klasse withing als mothods für sie gelten)

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

jedoch die ideale Position dieser Farbbalken sollte vertikal gewesen sein, als ich so etwas wie dies zu erreichen bin tring: (hier Bild)

enter image description here