2

I am looking to create a vertical section in a livechart. I have found examples of this but the code used is now depreciated.

This was my starting point: 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
  }
});

However I found that "FromValue" has changed to "Value" and "ToValue" has changed to "SectionWidth" and the section created is now horizontal instead of vertical. My code is in vb.net (as that is what I am developing in) but here is a sample:

Dim axissection As New impLiveChartsWPF.AxisSection
With axissection
  .Value = 1
  .SectionWidth = 1
  .Stroke = Brushes.YellowGreen
  .StrokeThickness = 1
  .StrokeDashArray = collection
End With

And this code creates a horizontal box that goes from 1 to 2 on the y axis. need a thin vertical line on the x axis to denote a change in parameters (like a system turning off or on).

Randy Ross
  • 23
  • 1
  • 4

1 Answers1

3

The key point for making the section vertical is to add the section to the X axis, not the Y axis. Adding to the X axis makes it vertical, adding to the Y axis makes it horizontal.

This makes the section vertical:

cartesianChart1.AxisX.Add(new Axis
{
    Sections = new SectionsCollection
    {
        axisSection
    }
});

Or in VB:

cartesianChart1.AxisX.Add(New Axis With {
    .Sections = New SectionsCollection From {
        axisSection
    }
})
gunnerone
  • 3,566
  • 2
  • 14
  • 18