Click here to Skip to main content
15,901,505 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i am using zedgraph in my program, it works good, when i load my it. but when i click on record button so as to insert other information, so the graph duplicated its bars for the same information, so i want to make it clear before i record or delete any information from database.
PLEASE help me

         try {

             // get a reference to the GraphPane
             GraphPane myPane = zg1.GraphPane;

             // Set the Titles
 myPane.Title.Text = "Les locations enregistrees dans la base de donnée";
 myPane.XAxis.Title.Text = "Les Locations";
 myPane.YAxis.Title.Text = "La durée du location & Prix du location";

             // Make up some data points
             int iNbLocations = 0;
         _bd.Command.CommandText = "SELECT COUNT(*) FROM locations";
             Debug.WriteLine( Environment.NewLine );
             Debug.WriteLine( _bd.Command.CommandText );
             _bd.Reader = _bd.Command.ExecuteReader();
             if (_bd.Reader.Read()) {
             iNbLocations = int.Parse(_bd.Reader[0].ToString());
             }//if
             _bd.Reader.Close();
             //Max = 5
             if (iNbLocations > 5) {
                 iNbLocations = 5;
             }//if
         //Initialisation de la taille des tableaux des données
             string[] labels = new string[iNbLocations];
             double[] y = new double[iNbLocations];
             double[] y2 = new double[iNbLocations];
                     _bd.Command.CommandText = "SELECT NbJourLocation,"+
                     "DateLocation, idLocations, PrixLocation " +
         "FROM Locations ORDER BY Idlocations desc LIMIT 5";

         Debug.WriteLine( Environment.NewLine );
         Debug.WriteLine( _bd.Command.CommandText );
         _bd.Reader = _bd.Command.ExecuteReader();
         for (int i=0; i<inblocations;i++)
                     if(_bd.Reader.Read()) {

     labels[i] = _bd.Reader["idLocations"].ToString();
     y[i] = double.Parse(_bd.Reader["NbJourLocation"].ToString());
     y2[i] = double.Parse(_bd.Reader["PrixLocation"].ToString());

             }//if

         }//for i
         _bd.Reader.Close();

         // Generate a red bar with "Curve 1" in the legend
BarItem myBar = myPane.AddBar(  "Nombres des Jours du Location", null, y,
                                       Color.GreenYellow );
    myBar.Bar.Fill = new Fill( Color.Red, Color.Azure,
                                       Color.Red );

     // Generate a blue bar with "Curve 2" in the legend
     myBar = myPane.AddBar( "Prix Location", null, y2, Color.Blue );
     myBar.Bar.Fill = new Fill( Color.Blue, Color.White,
                                       Color.Blue );



     // Draw the X tics between the labels instead of
     // at the labels
     myPane.XAxis.MajorTic.IsBetweenLabels = true;

     // Set the XAxis labels
     myPane.XAxis.Scale.TextLabels = labels;
     // Set the XAxis to Text type
     myPane.XAxis.Type = AxisType.Text;
     // Fill the Axis and Pane backgrounds
     myPane.Chart.Fill = new Fill( Color.White,
                        Color.FromArgb( 255, 255, 166), 90F );
     myPane.Fill = new Fill( Color.FromArgb( 250, 250, 255) );



     }//try
 catch (Exception ex) {
     Debug.WriteLine( Environment.NewLine );
     Debug.WriteLine( ex.Message );
         MessageBox.Show("Une erreur a été détectée : " +
                Environment.NewLine + ex.Message, "Erreur");
     }

     // Tell ZedGraph to refigure the
     // axes since the data have changed

     zg1.AxisChange();
Posted
Updated 29-Aug-11 6:55am
v4

Putting this right after the first line in the try block should do it.

C#
myPane.Clear() 


I feel your graph pain.
 
Share this answer
 
v2
Have you tried:
zg1.GraphPane.CurveList.Clear();
zg1.GraphPane.GraphObjList.Clear();
or
zg1.GraphPane = New GraphPane();
 
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