如何在实时图表中创建垂直线
How to Create a vertical line in livecharts
我想在实时图表中创建一个垂直部分。我找到了这方面的例子,但使用的代码现在已贬值。
这是我的出发点:
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 轴上需要一条细垂直线来表示参数的变化(比如系统关闭或打开)。
使截面垂直的关键点是将截面添加到 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
}
})
我想在实时图表中创建一个垂直部分。我找到了这方面的例子,但使用的代码现在已贬值。
这是我的出发点: 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 轴上需要一条细垂直线来表示参数的变化(比如系统关闭或打开)。
使截面垂直的关键点是将截面添加到 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
}
})