Thursday, 15 March 2018

c# chart


add ado.net to fetch data from sql

change chart type in series property



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 WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            using (testEntities1 _entity = new testEntities1())
            {
                List<spending> spending_list = new List<spending>();
                spending_list = _entity.spendings.ToList();

                dataGridView1.DataSource = spending_list;

                foreach(var item in spending_list)
                {
                    chart1.Series["spending"].Points.AddXY(item.category, item.percentage);
                }
            }
        }
    }
}



reference:
https://www.c-sharpcorner.com/article/crud-operation-using-entity-framework-in-windows-form-application/
https://www.c-sharpcorner.com/UploadFile/1e050f/chart-control-in-windows-form-application/
https://www.youtube.com/watch?v=6ua-IegyKB4

No comments:

Post a Comment