簡體   English   中英

如何在區間條形圖中繪制水平和垂直線 - oxyplot - WPF

[英]how to draw horizontal and vertical lines in interval bar chart - oxyplot - WPF

下午好,現在我有這個圖表,但我想在條形圖中添加紅色和藍色線條。 我非常喜歡與oxyplot。 謝謝你的幫助。

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

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

在此輸入圖像描述

這是我的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;
        }
    }

為他人:

using OxyPlot.Annotations;

double X = 0.0D;
double Y = 0.87825D;

LineAnnotation Line = new LineAnnotation()
{
    StrokeThickness = 1,
    Color = OxyColors.Green,
    Type = LineAnnotationType.Horizontal,
    Text = (Y).ToString(),
    TextColor = OxyColors.White,
    X = X,
    Y = Y
    };

myPlotViewModel.Annotations.Add(Line);

我使用Plotmodel.LineAannotation創建了垂直線,在Y軸中創建了帶有majorgridlinestyle的水平線,但也可以使用線注釋來完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM