Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How create chart in c# using data from excel . I try everithing but I don´t know what I should make . Need help !!§

I want create chart in c#(Microsoft Visual C# 2010 Express). It is Windows forms application and I want get data from Excel table this is part of my code
C#
/////////////////// 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 System.Data.OleDb; 

namespace WindowsFormsApplication1 
{ 
public partial class Form1 : Form 
{ public Form1() { InitializeComponent(); } private void chart1_Click(object sender, EventArgs e) { chart1.ChartAreas.Add("area"); chart1.ChartAreas["area"].AxisX.Minimum = 0; chart1.ChartAreas["area"].AxisX.Maximum = 20; chart1.ChartAreas["area"].AxisX.Interval =1 ; chart1.ChartAreas["area"].AxisY.Minimum = 0; chart1.ChartAreas["area"].AxisY.Interval =10 ; chart1.Series.Add("Meranie");
 chart1.Series["Meranie"].Color=Color.Green;
 chart1.Series["Meranie"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
 // 
} private void Form1_Load(object sender, EventArgs e) { 
// TODO: This line of code loads data into the 'databaseDataSet.Meranie' table. You can move, or remove it, as needed. 
// this.meranieTableAdapter.Fill(this.databaseDataSet.Meranie); 
} 

private void X_Click(object sender, EventArgs e) 
{ 
}

 private void button1_Click(object sender, EventArgs e) 
{ 
/* OleDbConnection conn = new OleDbConnection(); 
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; 
Data Source=C:\Users\Peto\Documents\Visual Studio 2010\Projects\Meranie vzduchu\Meranie vzduchu\bin\Tabulky.xls;Extended Properties= ""Excel 8.0;HDR=YES;"";";
 OleDbCommand command1 = new OleDbCommand ( "SELECT Meno " + "FROM [Studenti$]", conn ); OleDbCommand command2 = new OleDbCommand ( "SELECT Priezvisko " + "FROM [Studenti$]", conn ); DataSet dsMeno = new DataSet(); 
DataSet dsPriezvisko = new DataSet(); 
OleDbDataAdapter adapter1 = new OleDbDataAdapter(command1); 
adapter1.Fill(dsMeno); 
OleDbDataAdapter adapter2 = new OleDbDataAdapter(command2); 
adapter2.Fill(dsPriezvisko); */ 
} 

private void chart1_Enter(object sender, EventArgs e) 
{ 
chart1.ChartAreas.Add("area"); 
chart1.ChartAreas["area"].AxisX.Minimum = 0; 
chart1.ChartAreas["area"].AxisX.Maximum = 20; 
chart1.ChartAreas["area"].AxisX.Interval = 1; 
chart1.ChartAreas["area"].AxisY.Minimum = 0; 
chart1.ChartAreas["area"].AxisY.Interval = 10; 
chart1.Series.Add("Meranie"); chart1.Series["Meranie"].Color = Color.Green; chart1.Series["Meranie"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; 

/////////////////////////////////////////////////////////////////// // need some code ...... I need get data from excel and put graph ////////////////////////////////////////////////////////////// 
} 

private void button2_Click(object sender, EventArgs e) 
{ 
OleDbConnection conn = new OleDbConnection(); 
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Users\Peto\Documents\Visual Studio 2010\Projects\Meranie vzduchu\Meranie vzduchu\bin\Tabulky.xls;
Extended Properties= ""Excel 8.0;HDR=YES;"";";
Posted
Updated 3-Apr-13 8:55am
v2
Comments
Sergey Alexandrovich Kryukov 3-Apr-13 13:46pm    
Do you want to create a chart in Excel, or somewhere else?
What is the application type and UI library you want to use?
—SA

1 solution

It is farly straight forward:
http://support.microsoft.com/kb/302084[^]

Read the cells that contains the plotted data and you are done.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900