Problème d'affichage de charts

zeph245 Messages postés 12 Date d'inscription jeudi 25 septembre 2014 Statut Membre Dernière intervention 17 octobre 2014 - Modifié par BunoCS le 16/10/2014 à 17:36
zeph245 Messages postés 12 Date d'inscription jeudi 25 septembre 2014 Statut Membre Dernière intervention 17 octobre 2014 - 17 oct. 2014 à 19:03
Salut a tous j'ai un souci ici j'aimera apres un click afficher un chart et voila pluto ce qui s'affiche:


Bonjour,

2 réponses

zeph245 Messages postés 12 Date d'inscription jeudi 25 septembre 2014 Statut Membre Dernière intervention 17 octobre 2014
16 oct. 2014 à 14:29
voila mon code:
 protected void Button2_Click(object sender, EventArgs e)
{


DataSet ds = new DataSet();
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["supervisionConnectionString2"].ConnectionString);
conn.Open();
string cmdstr = "select DISTINCT ETAT_R,PSEUDO FROM BTS,SOURCE_ENERGIE_AUXILLIAIRE WHERE BTS.ID_SOURCE=SOURCE_ENERGIE_AUXILLIAIRE.ID_SOURCE ";
SqlCommand cmd = new SqlCommand(cmdstr, conn);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
dt = ds.Tables[0];



string[] x = new string[dt.Rows.Count];
int[] y = new int [dt.Rows.Count];


for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToInt32( dt.Rows[i][1]);
}
Chart1.Series[0].Points.DataBindXY(y, x);
Chart1.Series[0].ChartType = SeriesChartType.StackedBar100;
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
}

                
0
Whismeril Messages postés 19021 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 16 avril 2024 656
16 oct. 2014 à 15:33
Bonjour,

plutot qu'ne impression d'écran (pas très lisible) il faudrait retranscrire le message d'erreur.
Néanamoins, le databindingsource (XY ou non), selon mon expérience n'est pas très souple et fort lent.
Puisque tu faits une boucle pour remplir tes tableau x et y, autant ajouter les points directement à la série (qu'il faut initialiser avant), tu vas gagner en robustesse et temps d'excution.
Voilà un exmple quie marche avec des doubles en entrée

                Chart1.Series.Add("Ma série");
                Chart1.Series[0].IsXValueIndexed = true;
                Chart1.Series[0].ChartType = SeriesChartType.Line;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Chart1.Series[0].Points.Add(new DataPoint(dt.Rows[i][0].ToString(), Convert.ToInt32(  dt.Rows[i][1])));
                }


0
zeph245 Messages postés 12 Date d'inscription jeudi 25 septembre 2014 Statut Membre Dernière intervention 17 octobre 2014
16 oct. 2014 à 16:28
Voila pour une bonne visibilite

Server Error in '/WebSite1' Application.
Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 82:         {
Line 83: x[i] = dt.Rows[i][0].ToString();
Line 84: y[i] = Convert.ToInt32( dt.Rows[i][1]);
Line 85: }
Line 86: Chart1.Series[0].Points.DataBindXY(y, x);



Source File: c:\Users\Stephane\Documents\Visual Studio 2010\WebSites\WebSite1\al.aspx.cs Line: 84

Stack Trace:


[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +10896279
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +145
System.String.System.IConvertible.ToInt32(IFormatProvider provider) +46
System.Convert.ToInt32(Object value) +28
al.Button2_Click(Object sender, EventArgs e) in c:\Users\Stephane\Documents\Visual Studio 2010\WebSites\WebSite1\al.aspx.cs:84
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9633194
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
0
zeph245 Messages postés 12 Date d'inscription jeudi 25 septembre 2014 Statut Membre Dernière intervention 17 octobre 2014
16 oct. 2014 à 17:20
j'ai utilise ton code mais voila pluto ske j'ai maintenan coe erreur:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.UI.DataVisualization.Charting.DataPoint.DataPoint(double, double)' has some invalid arguments

Source Error:


Line 84:         for (int i = 0; i < dt.Rows.Count; i++)
Line 85: {
Line 86: Chart1.Series[0].Points.Add(new DataPoint(dt.Rows[i][0].ToString(), Convert.ToInt32(dt.Rows[i][1]))); c'est ici ke j'ai une erreur
Line 87: }
Line 88: //Chart1.Series[0].Points.DataBindXY(y, x);



Source File: c:\Users\Stephane\Documents\Visual Studio 2010\WebSites\WebSite1\al.aspx.cs Line: 86




Microsoft (R) Visual C# Compiler version 4.0.30319.18408

for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.

c:\Users\Stephane\Documents\Visual Studio 2010\WebSites\WebSite1\al.aspx.cs(86,41): error CS1502: The best overloaded method match for 'System.Web.UI.DataVisualization.Charting.DataPoint.DataPoint(double, double)' has some invalid arguments
c:\Users\Stephane\Documents\Visual Studio 2010\WebSites\WebSite1\al.aspx.cs(86,55): error CS1503: Argument 1: cannot convert from 'string' to 'double'


je c pa j'ai mem passei des double entre comme u la signaler mais le message persiste donc si u pe m'aider une foi de plus.
bonne reception
0
Whismeril Messages postés 19021 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 16 avril 2024 656
16 oct. 2014 à 20:29
Si tu as mis des doubles avec ToString(); alors c'est des strings... (j'ai oublié de l'enlever quand j'ai copié/ coller ton code...)
0
zeph245 Messages postés 12 Date d'inscription jeudi 25 septembre 2014 Statut Membre Dernière intervention 17 octobre 2014
17 oct. 2014 à 12:31
salut,
je m'excuse mais je ne comprend pa ton explication j'ai essaiei avec des string c toujours le mem message d'erreur si tu pe ecrire le pseudo code pour m'eclairer sur ta pensee
0
Whismeril Messages postés 19021 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 16 avril 2024 656
17 oct. 2014 à 13:40
 DataPoint(dt.Rows[i][0].ToString()

Ca c'est un string, je me suis trompé quand j'ai copié/coller.

Essaye
 Chart1.Series[0].Points.Add(new DataPoint(1.0, Convert.ToInt32(dt.Rows[i][1]))); 
juste pour voir s'il n'y a pas un autre problème.
0
Rejoignez-nous