List of Exercises

How to Make Cartesianchart in WinForms c#

	    
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Cartesianchart_Winforms
{

// NuGet\Install-Package LiveCharts -Version 0.9.7
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void CartesianChart1OnDataClick(object sender, ChartPoint chartPoint)
    {
      MessageBox.Show("You clicked (" + chartPoint.X + "," + chartPoint.Y + ")");
    }

    private void button1_Click(object sender, EventArgs e)
    {
      LiveCharts.WinForms.CartesianChart cartesianChart1 = new LiveCharts.WinForms.CartesianChart();
      cartesianChart1.Width = 500;
      cartesianChart1.Height = 200;
      cartesianChart1.Visible = false;
      cartesianChart1.Series = new SeriesCollection
      {
        new LineSeries
        {
          Title = "Series 1",
          Values = new ChartValues<double> {4, 6, 5, 2, 7}
        },
        new LineSeries
        {
          Title = "Series 2",
          Values = new ChartValues<double> {6, 7, 3, 4, 6},
          PointGeometry = null
        },
        new LineSeries
        {
          Title = "Series 3",
          Values = new ChartValues<double> {5, 2, 8, 3},
          PointGeometry = DefaultGeometries.Square,
          PointGeometrySize = 15
        }
      };

      cartesianChart1.AxisX.Add(new Axis
      {
        Title = "Month",
        Labels = new[] { "Jan", "Feb", "Mar", "Apr", "May" }
      });

      cartesianChart1.AxisY.Add(new Axis
      {
        Title = "Sales",
        LabelFormatter = value => value.ToString("C")
      });

      cartesianChart1.LegendLocation = LegendLocation.Right;

      //modifying the series collection will animate and update the chart
     /*  cartesianChart1.Series.Add(new LineSeries
       {
         Values = new ChartValues<double> { 5, 3, 2, 4, 5 },
         LineSmoothness = 0, //straight lines, 1 really smooth lines
         PointGeometry = System.Windows.Media.Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"),
         PointGeometrySize = 50,
         PointForeground = System.Windows.Media.Brushes.Gray
       });*/

      //modifying any series values will also animate and update the chart
      cartesianChart1.Series[2].Values.Add(5d);


      cartesianChart1.DataClick += CartesianChart1OnDataClick;

      this.panel1.Controls.Clear();
      this.panel1.Controls.Add(cartesianChart1);
      cartesianChart1.Visible = true;
    }
  }
}

		
	 


Download the project of Visual Studio 2013 in DropBox Download


How to Make a Cartesian Chart in C# WinForms with LiveCharts


Video Thumbnail