Click here to Skip to main content
12,077,911 members (49,314 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# MySQL
hai
i have tried to write the coding for presenting a graph from mysql database data in C# coding but i get the error like chart1 is not excit in the current context.

I don't know how to clear the error if u have any idea please reply me

I attached the following code I did

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.Web;
//using System.Web.UI;
//using System.Web.UI.WebControls;
using System.Windows.Forms.DataVisualization.Charting;
using MySql.Data.MySqlClient;
 
namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
   
        public Form1()
        {
            InitializeComponent();
            MySqlConnection con = new MySqlConnection();
            //Chart Chart1.Series["Series1"].ChartType = SeriesChartType.Column;
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            Chart1.Series["Series1"].ChartType = SeriesChartType.Column;
            try
            {
            // TODO: This line of code loads data into the 'testDataSet.periodicdata' table. You can move, or remove it, as needed.
            this.periodicdataTableAdapter.Fill(this.testDataSet.periodicdata);
             MySqlConnection con = new MySqlConnection();
            con.ConnectionString = "server=localhost;user id=root;password=vinoth;database=test";
            MySqlCommand cmd = new MySqlCommand();
 
           
                //con.ConnectionString = "server=localhost;user id=root;password=******;database=test";
                //con.ConnectionString = "server=.\\mysqlexpress;database=test;integrated security=true;";
                con.Open();
        
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }
 

        private void button1_Click(object sender, EventArgs e)
        {
            Chart1.Series["Series1"].ChartType = SeriesChartType.Column;
            Chart1.Series["Series1"]["DrawingStyle"] = "Emboss";
            //Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
            Chart1.Series["Series1"].IsValueShownAsLabel = true;
 
            FillData();
        }
 
        private void FillData()
        {
            DataTable dt = new DataTable();
            DataColumn dc;
 
            dc = new DataColumn();
            dc.ColumnName = "date_time";
            dt.Columns.Add(dc);
            dc = new DataColumn();
            dc.ColumnName = "Volt1";
            dt.Columns.Add(dc);
 
            Chart1.DataSource = dt;
            Chart1.Series["Series1"].XValueMember = "date_time";
            Chart1.Series["Series1"].YValueMembers = "Volt1";
            Chart1.DataBind();
            //throw new NotImplementedException();
        }
    }
}
Posted 28-Jan-13 1:33am
Edited 28-Jan-13 1:40am
StM0n13.4K
v2
Comments
s_mon 28-Jan-13 6:44am
   
On which line did the error occur?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try using zedgraph, see this link: ZedGraph in a C# web application in a Medium trust environment[^]

Good Luck,
z3ngew
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

hello you can direct draw graph by using ajax new functinality for drawing graph.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160212.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100