Simple 2D Chart
With LightningCharts DLLs included in your project, you are ready to create your first chart. We will begin with creating a simple line chart for WinForms and WPF platforms without MVVM implementation.
The chart can be added to a designer (e.g. Form, Window, or other containers) and configured by using Properties window. However, this tutorials series shows how to create everything in code, thereby providing the best way for maintainability in further project development.
Declare a LightningChart instance.
// Create chart instance. var chart = new LightningChartUltimate();
Set the parent container of the chart where it will be rendered.
Windows Forms:
// Set parent container of chart. chart.Parent = this; chart.Dock = DockStyle.Fill;
WPF:
// Set the parent container of chart. (Content as Grid).Children.Add(chart);
Create linear series, e.g. PointLineSeries.
// New line-series instance is assigned to default X and Y axes. var series = new PointLineSeries( chart.ViewXY, chart.ViewXY.XAxes[0], chart.ViewXY.YAxes[0] );
Generate some random data or convert from source to appropriate format.
// Scatter data randomly. Random rand = new Random(); int pointsCount = 70; // Generate some data with your algorithm. var data = new SeriesPoint[pointsCount]; for (int i = 0; i < pointsCount; i++) { data[i].X = (double)i; // “Your double X-value”; data[i].Y = rand.Next(0, 100); // “Your double Y-value”; }
Set generated data-points into series.
series.Points = data; // Assign data.
Add created linear series to chart collection of specific series type.
// Add the series into list of point-line-series. chart.ViewXY.PointLineSeries.Add(series);
Autoscale chart axes to show all series data-points.
// Autoscale view according to given data. chart.ViewXY.ZoomToFit();
Build and Run the application.