How to make a WinForms line chart

Need help in implementing some specific function to your LightningChart Ultimate powered application? Post a question and get code snippets from other LightningChart Ultimate community members.

How to make a WinForms line chart

Postby ArctionPasi » Tue Oct 04, 2016 1:46 pm

To make a very simple WinForms line chart, here is how...

Just add empty Form in the application, and apply the following code in it. CreateChart method creates the chart instance, and also creates the series. Chart line style is defined, and also points style. Both line and points are shown in this method.

Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Arction.WinForms.Charting;
using Arction.WinForms.Charting.Axes;
using Arction.WinForms.Charting.Views;
using Arction.WinForms.Charting.Views.ViewXY;
using Arction.WinForms.Charting.SeriesXY;

 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        LightningChartUltimate _chart;


        public Form1()
        {
            InitializeComponent(); //This row is created already by Visual Studio.

            CreateChart();   
        }


       
        void CreateChart()
        {
            _chart = new LightningChartUltimate();
            _chart.Parent = this;
            _chart.Dock = DockStyle.Fill;

            //BeginUpdate...EndUpdate is recommended to be used around chart property settings,
            //so that the chart doesn't refresh every time when setting is changed. We only
            //need to update it once.
            _chart.BeginUpdate();

            //Set axis labels to numbers
            _chart.ViewXY.XAxes[0].ValueType = AxisValueType.Number;

            //Create point line series
            PointLineSeries pls = new PointLineSeries(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
           
            //Set line style
            pls.LineStyle.Width = 1.5f;
            pls.LineStyle.Color = Color.Yellow;
            pls.LineVisible = true;

            //Set point style
            pls.PointStyle.Shape = Shape.Circle;
            pls.PointStyle.GradientFill = GradientFillPoint.Solid;
            pls.PointStyle.Color1 = Color.OrangeRed;
            pls.PointStyle.BorderColor = Color.Orange;
            pls.PointStyle.BorderWidth = 1.5f;
            pls.PointsVisible = true;

            pls.Points = GeneratePoints();

            _chart.ViewXY.PointLineSeries.Add(pls);

             //Zoom to fit
            _chart.ViewXY.ZoomToFit();

            _chart.EndUpdate();
        }


        SeriesPoint[] GeneratePoints()
        {
            int count = 100;
            SeriesPoint[] points = new SeriesPoint[count];
            Random rand = new Random();

            for (int i = 0; i < count; i++)
            {
                points[i].X = i;
                points[i].Y = rand.NextDouble() * 10.0;
            }
            return points;
        }
    }
}


The line chart application shows like this
WinformsLineChart.jpg
WinForms line chart example
WinformsLineChart.jpg (123.67 KiB) Viewed 2909 times
LightningChart Support Team, PT
User avatar
ArctionPasi
 
Posts: 1362
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland

Return to LightningChart Ultimate How-To's

Who is online

Users browsing this forum: No registered users and 2 guests

cron