Back to Devexpress

FinancialSeriesViewBase.LevelLineLength Property

corelibraries-devexpress-dot-xtracharts-dot-financialseriesviewbase-46dd710e.md

latest10.6 KB
Original Source

FinancialSeriesViewBase.LevelLineLength Property

Gets or sets a value specifying the length (in axis units) of the level line in financial series.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XtraChartsLocalizableCategory(XtraChartsCategory.Layout)]
public double LevelLineLength { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Layout)>
Public Property LevelLineLength As Double

Property Value

TypeDescription
Double

A Double value which represents the length of a level line in axis units , where an axis unit is the distance between two major values on the axis. This value should be greater than or equal to 0.

|

Remarks

The LevelLineLength property specifies the length of a level line in all Financial Series (Stock Series and Candle Stick Series). Since this property’s value is measured as a fraction of axis units , this allows its length to be automatically resized when the size of a Chart is changed. For instance, if the LevelLineLength property is set to 0.5 , then the length of every level line will always be equal to half the range between two major values on the axis.

For instance, these are the level lines in the Stock Series view.

Example

This example creates a ChartControl with a series of the StockSeriesView type and adds this chart to a form at runtime. Before you proceed with this example, create a Windows Forms Application in Visual Studio and include all necessary assemblies in the References list of your project.

For more information about the features of financial charts, refer to the following help topic: Financial Charting

csharp
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraCharts;
//...
    private void Form1_Load(object sender, EventArgs e) {
        // Create a new chart.
        ChartControl stockChart = new ChartControl();

        // Create a stock series.
        Series series1 = new Series("Series 1", ViewType.Stock);

        // Bind the series to data.
        series1.DataSource = GetDataPoints();
        series1.SetFinancialDataMembers("Argument", "Low", "High", "Open", "Close");

        // Specify that date-time arguments are expected.
        series1.ArgumentScaleType = ScaleType.DateTime;

        // Add the series to the chart.
        stockChart.Series.Add(series1);

        // Customize the series view settings.
        StockSeriesView view = (StockSeriesView)series1.View;

        view.LineThickness = 2;
        view.LevelLineLength = 0.25;

        // Specify the series reduction options.
        view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue;
        view.ReductionOptions.Level = StockLevel.Close;
        view.ReductionOptions.Visible = true;

        // Set point colors.
        view.Color = Color.Green;
        view.ReductionOptions.Color = Color.Red;

        // Access the chart's diagram.
        XYDiagram diagram = (XYDiagram)stockChart.Diagram;

        // Exclude empty ranges from the X-axis range
        // to avoid gaps in the chart's data.
        diagram.AxisX.DateTimeScaleOptions.SkipRangesWithoutPoints = true;

        // Hide the range without points at the beginning of the y-axis.
        diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false;

        // Hide the legend.
        stockChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;

        // Add a title to the chart.
        stockChart.Titles.Add(new ChartTitle());
        stockChart.Titles[0].Text = "Stock Chart";

        // Add the chart to the form.
        stockChart.Dock = DockStyle.Fill;
        this.Controls.Add(stockChart);
    }

    List<DataPoint> GetDataPoints() {
        List<DataPoint> dataPoints = new List<DataPoint> {
            new DataPoint(DateTime.Now.AddDays(-9), 24.00, 25.00, 25.00, 24.875),
            new DataPoint(DateTime.Now.AddDays(-8), 23.625, 25.125, 24.00, 24.875),
            new DataPoint(DateTime.Now.AddDays(-7), 26.25, 28.25, 26.75, 27.00),
            new DataPoint(DateTime.Now.AddDays(-6), 26.50, 27.875, 26.875, 27.25),

            new DataPoint(DateTime.Now.AddDays(-4), 25.75, 26.875, 26.75, 26.00),
            new DataPoint(DateTime.Now.AddDays(-3), 25.75, 26.75, 26.125, 26.25),
            new DataPoint(DateTime.Now.AddDays(-2), 25.75, 26.375, 26.375, 25.875),
            new DataPoint(DateTime.Now.AddDays(-1), 24.875, 26.125, 26.00, 25.375),
            new DataPoint(DateTime.Now.AddDays(0), 25.125, 26.00, 25.625, 25.75),
            };
        return dataPoints;
    }
}
public class DataPoint {
    public DateTime Argument { get; set; }
    public double Low { get; set; }
    public double High { get; set; }
    public double Open { get; set; }
    public double Close { get; set; }
    public DataPoint(DateTime arg, double low, double high, double open, double close) {
        this.Argument = arg;
        this.Low = low;
        this.High = high;
        this.Open = open;
        this.Close = close;
    }
}
vb
using System
using System.Collections.Generic
using System.Drawing
using System.Windows.Forms
using DevExpress.XtraCharts
'...
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        ' Create a new chart.
        Dim stockChart As ChartControl = New ChartControl()

        ' Create a stock series.
        Dim series1 As Series = New Series("Series 1", ViewType.Stock)

        ' Bind the series to data.
        series1.DataSource = GetDataPoints()
        series1.SetFinancialDataMembers("Argument", "Low", "High", "Open", "Close")

        ' Specify that date-time arguments are expected.
        series1.ArgumentScaleType = ScaleType.DateTime

        ' Add the series to the chart.
        stockChart.Series.Add(series1)

        ' Customize the series view settings.
        Dim view As StockSeriesView = CType(series1.View, StockSeriesView)
        view.LineThickness = 2
        view.LevelLineLength = 0.25

        ' Specify the series reduction options.
        view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue
        view.ReductionOptions.Level = StockLevel.Close
        view.ReductionOptions.Visible = True

        ' Set point colors.
        view.Color = Color.Green
        view.ReductionOptions.Color = Color.Red

        ' Access the chart's diagram.
        Dim diagram As XYDiagram = CType(stockChart.Diagram, XYDiagram)

        ' Exclude empty ranges from the X-axis range
        ' to avoid gaps in the chart's data.
        diagram.AxisX.DateTimeScaleOptions.SkipRangesWithoutPoints = True

        ' Hide the range without points at the beginning of the y-axis.
        diagram.AxisY.WholeRange.AlwaysShowZeroLevel = False

        ' Hide the legend.
        stockChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.[False]

        ' Add a title to the chart.
        stockChart.Titles.Add(New ChartTitle())
        stockChart.Titles(0).Text = "Stock Chart"

        ' Add the chart to the form.
        stockChart.Dock = DockStyle.Fill
        Me.Controls.Add(stockChart)
    End Sub

    Private Function GetDataPoints() As List(Of DataPoint)
        Dim dataPoints As List(Of DataPoint) = New List(Of DataPoint) From {
            New DataPoint(Date.Now.AddDays(-9), 24.00, 25.00, 25.00, 24.875),
            New DataPoint(Date.Now.AddDays(-8), 23.625, 25.125, 24.00, 24.875),
            New DataPoint(Date.Now.AddDays(-7), 26.25, 28.25, 26.75, 27.00),
            New DataPoint(Date.Now.AddDays(-6), 26.50, 27.875, 26.875, 27.25),

            New DataPoint(Date.Now.AddDays(-4), 25.75, 26.875, 26.75, 26.00),
            New DataPoint(Date.Now.AddDays(-3), 25.75, 26.75, 26.125, 26.25),
            New DataPoint(Date.Now.AddDays(-2), 25.75, 26.375, 26.375, 25.875),
            New DataPoint(Date.Now.AddDays(-1), 24.875, 26.125, 26.00, 25.375),
            New DataPoint(Date.Now.AddDays(0), 25.125, 26.00, 25.625, 25.75)
        }
        Return dataPoints
    End Function

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the LevelLineLength property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-chart-create-candlestick-chart/VB/CandleStickChart/Form1.vb#L31

vb
view.LineThickness = 2
view.LevelLineLength = 0.25
' Specify the series reduction options.

See Also

LineThickness

FinancialSeriesViewBase Class

FinancialSeriesViewBase Members

DevExpress.XtraCharts Namespace