我正在寻找在实时图表中创建垂直部分。我已经找到了这样的示例,但是现在使用的代码已贬值。
这是我的出发点: Found picture
var axisSection = new AxisSection
{
FromValue = index,
ToolTip = "dfsdf",
ToValue = index,
Stroke = Brushes.YellowGreen,
StrokeThickness = 1,
StrokeDashArray = new DoubleCollection(new[] { 4d })
};
chart.VisualElements.Add(new VisualElement
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
UIElement = new TextBlock //notice this property must be a wpf control
{
Text = journalObj.Title,
FontWeight = FontWeights.Bold,
Foreground = Brushes.Snow,
FontSize = 12,
Opacity = 0.6
}
});
但是,我发现“ FromValue”已更改为“ Value”,“ ToValue”已更改为“ SectionWidth”,并且创建的部分现在是水平的,而不是垂直的。我的代码在vb.net中(这就是我正在开发的代码),但这是一个示例:
Dim axissection As New impLiveChartsWPF.AxisSection
With axissection
.Value = 1
.SectionWidth = 1
.Stroke = Brushes.YellowGreen
.StrokeThickness = 1
.StrokeDashArray = collection
End With
并且此代码创建一个水平框,该水平框在y轴上从1变为2。在x轴上需要一条细的垂直线来表示参数的变化(例如系统关闭或打开)。
答案 0 :(得分:2)
使截面垂直的关键是将截面添加到X轴,而不是Y轴。添加到X轴使其垂直,添加到Y轴使其水平。
这使该部分垂直:
cartesianChart1.AxisX.Add(new Axis
{
Sections = new SectionsCollection
{
axisSection
}
});
或在VB中:
cartesianChart1.AxisX.Add(New Axis With {
.Sections = New SectionsCollection From {
axisSection
}
})