2017-08-21 229 views
2

下午好,現在我有這張圖表,但我想在條形圖中添加紅色和藍色線條。即時新聞與氧吧。謝謝你的幫助。如何在間隔條形圖中繪製水平和垂直線條 - oxyplot - WPF

我目前正在將繼電器中的事件顯示保存爲布爾值。所以有一個水平線參考是很好的。

藍線只是表示系統中事件的另一條線。

enter image description here

這是我的XAML

<Window x:Class="Label_Issue.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:Label_Issue" 
    xmlns:oxy="http://oxyplot.org/wpf" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid> 
    <oxy:PlotView x:Name="barChartModel"/> 
</Grid> 

這是我的.cs

namespace Label_Issue 
{ 

    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 

      SetUtilizationData(); 
     } 

     public PlotModel PlotModel { get; set; } 
     private void SetUtilizationData() 
     { 
      PlotModel = new PlotModel 
      { 

       LegendOrientation = LegendOrientation.Vertical, 
       LegendPlacement = LegendPlacement.Outside, 
       LegendPosition = LegendPosition.RightTop 
      }; 


      // define x-axis 
      OxyPlot.Axes.DateTimeAxis dateAxis = new OxyPlot.Axes.DateTimeAxis 
      { 
       Position = OxyPlot.Axes.AxisPosition.Bottom, 
       //StringFormat = "dd/MM/yy HH:mm"   // automatisch? 
      }; 

      // add to plotmodel.axes 
      PlotModel.Axes.Add(dateAxis); 


      // define y-axis 
      CategoryAxis categoryAxis = new CategoryAxis 
      { 
       Position = AxisPosition.Left, 
      }; 

      //add to plotmodel.axes 
      PlotModel.Axes.Add(categoryAxis); 

      IntervalBarSeries barSeries = new OxyPlot.Series.IntervalBarSeries 
      { 
       LabelMargin = 0 
      }; 

      TestData td = new TestData(); 
      for(int index=0; index<10;index++) 
      { 
       IntervalBarItem item = new IntervalBarItem 
       { 

        Start = OxyPlot.Axes.DateTimeAxis.ToDouble(new DateTime(2017, 04, 01, 06, 00 + index, 00)), 
        End = OxyPlot.Axes.DateTimeAxis.ToDouble(new DateTime(2017, 04, 01, 07, 00 + index, 00)), 
        CategoryIndex = index, 
        Title = "test" 
       }; 
       barSeries.Items.Add(item); 
      } 

      PlotModel.Series.Add(barSeries); 
      barChartModel.Model = PlotModel; 
     } 
    } 

回答

0

我所做的垂線與Plotmodel.LineAannotation與水平線在Y軸上有biggridlinestyle,但是可以完成還有一個線條註釋。

相關問題