Grazie ancora una volta.
>>>> Atrimenti e' fermo alla posizione -1.
La posizione -1 corrisponde al valore restituito a video -59con il Response.Write(reader["VarPerc"].ToString()); ?
Se fosse così va bene perchè devo prendere solo quello restituito dalla myQuery, che è solo uno,
Chart1 è la generazione di un grafico tramite la classe chart controls per .NET Framework.
codice:
String myQuery = " SELECT tNome, tAnnoPrecedente, " +
" VariazionePercentuale As VarPerc " +
" FROM tbl_m " +
" WHERE " +
" tNome LIKE '%Pippo%'; ";
OdbcConnection myConnectionString =
new OdbcConnection(
ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);
myConnectionString.Open();
OdbcCommand objCmd = new OdbcCommand(myQuery, myConnectionString);
objCmd.Prepare();
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = myQuery;
OdbcDataReader reader = objCmd.ExecuteReader();
Chart1.DataSource = reader; //COSì NON SI GENERA IL GRAFICO
Chart1.DataBind();
//Chart1.DataSource = objCmd.ExecuteReader(); //COSì SI GENERA IL GRAFICO
while (reader.Read())
Response.Write(reader["VarPerc"].ToString());
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 0;
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Angle = 0;
Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = false;
.......
DateTime dateTime = new DateTime(DateTime.Now.AddYears(-1).Year, 12, DateTime.Now.Day);
string s3 = dateTime.ToString("MMM yyy");
Chart1.Series.Add(s3);
Chart1.Series[s3].LabelFormat = "0.#";
Chart1.Series[s3].XValueMember = "tNome";
Chart1.Series[s3].YValueMembers = "tAnnoPrecedente";
Chart1.Series[s3].ChartType = SeriesChartType.Column;
Chart1.Series[s3]["PointWidth"] = "0.85";
Chart1.Series[s3].IsValueShownAsLabel = true;
Chart1.Series[s3]["PixelPointDepth"] = "1.0";
Chart1.Series[s3]["DrawingStyle"] = "Cylinder";
Chart1.Series[s3].Font = new System.Drawing.Font("Verdana", 9, FontStyle.Bold);
Chart1.Series[s3].LabelForeColor = System.Drawing.Color.FromArgb(0, 0, 128);
Chart1.Series[s3]["LabelStyle"] = "Top";
Chart1.Series[s3].Color = System.Drawing.Color.FromArgb(0, 0, 205);
Chart1.Legends.Add(new Legend(s3));
Chart1.Legends[s3].BackGradientStyle = GradientStyle.DiagonalLeft;
Chart1.Legends[s3].BorderColor = Color.Black;
Chart1.Legends[s3].BorderWidth = 2;
Chart1.Legends[s3].BorderDashStyle = ChartDashStyle.Solid;
Chart1.Legends[s3].ShadowOffset = 2;
Chart1.Legends[s3].Docking = Docking.Bottom;
Chart1.Legends[s3].Alignment = System.Drawing.StringAlignment.Center;
Chart1.Legends[s3].Font = new System.Drawing.Font("Verdana", 12, FontStyle.Bold);
Chart1.Series[s3].Legend = s3;
String top = reader["VarPerc"].ToString();
LegendItem newItem = new LegendItem();
newItem.ImageStyle = LegendImageStyle.Marker;
newItem.MarkerStyle = MarkerStyle.Diamond;
newItem.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.MiddleLeft);
newItem.Cells.Add(LegendCellType.Text, "top", ContentAlignment.MiddleLeft);
newItem.Cells[1].CellSpan = 2;
newItem.Cells.Add(LegendCellType.Text, "", ContentAlignment.MiddleLeft);
newItem.Cells.Add(LegendCellType.Text, top, ContentAlignment.MiddleLeft);
Chart1.Legends[0].CustomItems.Add(newItem);
reader.Dispose();
reader.Close();
objCmd.Dispose();
objCmd.Cancel();
myConnectionString.Dispose();
myConnectionString.Close();