gpt4 book ai didi

c# - 设置 IntervalBarSeries 的标签(oxyplot)

转载 作者:行者123 更新时间:2023-11-30 23:15:01 26 4
gpt4 key购买 nike

enter image description here我正在尝试将自己的标签文本设置在 IntervalBarSeries 上,但它只显示丑陋的 DateTime.ToDouble()-Value。 Title = "anyText" 不影响任何内容。有任何想法吗?下一个问题是,IntervalBarSeries 没有 Style 属性...

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

最佳答案

你得到这个结果,因为你改变了 LabelFormatString 的格式:

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

默认情况下 LabelFormatString 的值为:{2} (Title)

因此,只需将其删除即可得到正确的结果。

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

关于c# - 设置 IntervalBarSeries 的标签(oxyplot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42806085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com