2017-03-15 4 views
1

enter image description here Ich versuche, meinen eigenen labeltext auf der IntervalBarSeries gesetzt, aber es zeigt nur die hässliche DateTime.ToDouble() - Wert. Title = "anyText" betrifft nichts. Irgendwelche Ideen? Nächstes Problem ist, dass IntervalBarSeries keine Style-Eigenschaft haben ...Set Label von IntervalBarSeries (oxyplot)

MCVE:

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> 
</Window> 

CS-:

using OxyPlot; 
using OxyPlot.Axes; 
using OxyPlot.Series; 
using System; 
using System.Collections.Generic; 
using System.Collections.ObjectModel; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

namespace Label_Issue 
{ 
    /// <summary> 
    /// Interaktionslogik für MainWindow.xaml 
    /// </summary> 
    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, 
       LabelFormatString = "{0:.0}", 
      }; 

      TestData td = new TestData(); 
      foreach (TestDataItem data in td) 
      { 
       IntervalBarItem item = new IntervalBarItem 
       { 
        Start = OxyPlot.Axes.DateTimeAxis.ToDouble(data.start), 
        End = OxyPlot.Axes.DateTimeAxis.ToDouble(data.end), 
        CategoryIndex = 0, 
        Title = "test" 
       }; 
       barSeries.Items.Add(item); 
      } 

      PlotModel.Series.Add(barSeries); 
      barChartModel.Model = PlotModel; 
     } 
    } 
    public class TestData : ObservableCollection<TestDataItem> 
    { 
     public TestData() 
     { 
      Add(new TestDataItem() 
      { 
       start = new DateTime(2017, 04, 01, 06, 00, 00), 
       end = new DateTime(2017, 04, 01, 06, 30, 00), 
      }); 
     } 
    } 
    public class TestDataItem 
    { 

     public DateTime start { get; set; } 
     public DateTime end { get; set; } 
    } 
} 
+0

Können Sie 'MCVE' bereitstellen? –

+0

Ich habe ein MCVE mit einem barItem hinzugefügt –

+0

Ich schrieb eine Antwort, wenn Sie irgendwelche Q haben, nur ping mich im [WPF chat] (http://chat.stackoverflow.com/rooms/18165/wpf) –

Antwort

1

Sie dieses Ergebnis erhalten, weil Sie haben das Format für LabelFormatString geändert:

IntervalBarSeries barSeries = new OxyPlot.Series.IntervalBarSeries 
{ 
    LabelMargin = 0, 
    LabelFormatString = "{0:.0}", 
}; 

standardmäßig LabelFormatString hat Wert: {2} (Title)

Also, es ist einfach zu entfernen und dann werden Sie in der Lage richtiges Ergebnis zu bekommen.

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

danke sehr viel ! –