IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

Probleme de creation de graph avec ZedGraph


Sujet :

Windows Forms

  1. #1
    Membre actif
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    614
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 614
    Points : 299
    Points
    299
    Par défaut Probleme de creation de graph avec ZedGraph
    Bonjour,
    je souhaiterai creer un graphique a partir d"information stocké dans ma base de données.
    j'ai commencé par regarder le wiki de zedgraph et trouvé pas mal de chose.
    J'ai bien les informations qui vont bien mais cependant, j'ai un probleme d'affichage.
    Des que je lance ma form contenant lmon grpah l'echelle X est beaucoup trop grande.
    je ne trouve pas comment l'ajuster a mon contenu (dans mon cas 12, c'est sur l'annéé)

    Voci le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
     
            private void CreateGraph(ZedGraphControl zgc)
            {
                GraphPane myPane = zgc.GraphPane;
                PointPairList list = new PointPairList();
     
                // Set the titles and axis labels
                myPane.Title.Text = "My Test Graph";
                myPane.XAxis.Title.Text = "X Value";
                myPane.YAxis.Title.Text = "My Y Axis";
                myPane.XAxis.Type = AxisType.Date;
                myPane.XAxis.Scale.MinorUnit = DateUnit.Day;
                myPane.XAxis.Scale.MajorUnit = DateUnit.Day;
                myPane.XAxis.Scale.Format = "dd-MM-yy";
     
                double[] ya = new double[30];//{ 100, 115, 75, 22, 98, 40 };
                double[] x = new double[30];
                for (int i = 0; i < 30; i++)
                {
                    x[i] = (double)new XDate(2008, 12, i);
                    ya[i] = (10 * i);
     
     
                }
     
                BarItem myBar = myPane.AddBar("Curve 1", x, ya,
                                                     Color.Red);
                myBar.Bar.Fill = new Fill(Color.Aqua, Color.White,
                                                            Color.Aqua);
     
     
     
                // Calculate the Axis Scale Ranges
                zgc.AxisChange();
            }
     
            private void CreateGraph(GraphPane myPane)
            {
                OleDbConnection con = null;
                OleDbCommand command = null;
                String cs = "provider=Microsoft.JET.OLEDB.4.0; " + "data source =" + Environment.CurrentDirectory + "\\Content\\ADC.mdb;";
                OleDbDataReader dr = null;
     
              //  GraphPane myPane = zgc.GraphPane;
     
     
                myPane.Title.Text = "Répartition du CA par mois";
                myPane.XAxis.Title.Text = "Mois";
                myPane.YAxis.Title.Text = "CA en miller d'€";
                myPane.XAxis.Type = AxisType.Date;
                myPane.XAxis.Scale.MinAuto = true;
                myPane.XAxis.Scale.MinorUnit = DateUnit.Month;
                myPane.XAxis.Scale.MajorUnit = DateUnit.Month;
                myPane.XAxis.Scale.Format = "MMM-yyyy";
     
                PointPairList list = new PointPairList();
     
                int iMonth = 1;
                double[] ya = new double[13];//{ 100, 115, 75, 22, 98, 40 };
                double[] x = new double[13];
                //int i = 0;
                con = new OleDbConnection(cs);
     
                for (iMonth = 1; iMonth < 13; iMonth++)
                {
                    command = new OleDbCommand("SELECT Sum(TotalHT) As SUM_Month FROM tblClients where Month(DateContrat)=" + iMonth, con);
                    con.Open();
                    dr = command.ExecuteReader();
     
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            x[iMonth] = (double)new XDate(2008, iMonth, 1);
                            try
                            {
                                ya[iMonth] = Double.Parse(dr.GetValue(0).ToString());
                            }
                            catch (Exception)
                            {
                                ya[iMonth] = 0;
                            }
                            //i++;
                        }
                        con.Close();
                    }
                    else
                    {
                        MessageBox.Show("No result for your Data", "Infos",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                    // Fill the axis background with a color gradient
                    myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(204, 204, 255), 45.0F);
                    BarItem myBar = myPane.AddBar("", x, ya,Color.Red);
                    myBar.Bar.Fill = new Fill(Color.Aqua, Color.White,Color.Aqua);
                    myPane.AxisChange();
     
                    myPane.YAxis.Scale.Max += myPane.YAxis.Scale.MajorStep;
     
                BarItem.CreateBarLabels(myPane, false, "f0");
     
            }
    cf copie d'ecran1 pour avoir un apercu de mon probleme.
    et la copie d'ecran 2 pour ce que je souhaiterai avoir a l'affichage de ma form (sans avoir a zoomé)

    merci de votre aide

  2. #2
    Membre habitué Avatar de bobmidou
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    121
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Avril 2008
    Messages : 121
    Points : 149
    Points
    149
    Par défaut
    Salut

    Essaye de commencer par 0

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    ....
    double[] ya = new double[12];//{ 100, 115, 75, 22, 98, 40 };
    double[] x = new double[12];
    //int i = 0;
    con = new OleDbConnection(cs);
    for (iMonth = 0; iMonth < 12; iMonth++)
    {
         ...
         // tu peux ajouter 1 à iMonth
         x[iMonth] = (double)new XDate(2008, iMonth + 1, 1);
          .....
    Bonne chance

  3. #3
    Membre actif
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    614
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 614
    Points : 299
    Points
    299
    Par défaut
    non toujours la meme chose.

  4. #4
    Membre actif
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    614
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 614
    Points : 299
    Points
    299
    Par défaut
    j'ai trouvé la solution;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
                myPane.XAxis.Scale.MinorStep = 1.0;
                myPane.XAxis.Scale.MajorStep = 1.0;
                myPane.XAxis.Scale.Format = "dd/MM/yy";
                myPane.XAxis.Scale.MinorUnit = DateUnit.Month;
                myPane.XAxis.Scale.MajorUnit = DateUnit.Month;
                myPane.XAxis.Scale.Min = (double)new XDate((DateTime.Now.Year-2), 12, 1);
                myPane.XAxis.Scale.Max = (double)new XDate((DateTime.Now.Year), 1, 1);
                myPane.AxisChange();

  5. #5
    Membre actif
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    614
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 614
    Points : 299
    Points
    299
    Par défaut
    je reouvre ce topic parceque je me suis rendu compte qu'en faisant un clic droit et en choisissant 'set scale to default' j'obtiens a nouveau un graphe ilisible (cf cp ecran1).
    Est ce quelqu'un a deja utiliser ZedGraph avec des dates en abscisse?
    merci

Discussions similaires

  1. probleme de creation une BD avec Webmin
    Par khallou2007 dans le forum MySQL
    Réponses: 4
    Dernier message: 11/02/2009, 10h40
  2. Réponses: 2
    Dernier message: 24/11/2006, 13h30
  3. probleme de creation de dossier avec free
    Par byvan dans le forum Langage
    Réponses: 1
    Dernier message: 24/07/2006, 20h11
  4. Réponses: 8
    Dernier message: 08/06/2006, 15h48
  5. [C#] Probleme de creation de fichier avec Stream
    Par freddyboy dans le forum C#
    Réponses: 7
    Dernier message: 07/06/2004, 11h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo