tracer un graph à partir d'une base de données
bonjour,
a partir d'une base de donnée, j'essaie de faire un graphique avec ZedGraph.
J'y arrive très bien à tracer simplement une courbe ou autre.
Seulement, j'aimerais tracer les graph à partir des donnée étant dans ma base de donnée.
Pour ce faire je prend mon dernier ID de la base de donnée récupérée au préalable, et je remonte ma base de donnée pour tracer ma courbe.
Code:
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
|
private void CreateGraph4(ZedGraphControl zgc_data_lum_out)
{
GraphPane myPane = zgc_data_lum_out.GraphPane;
// Set the titles and axis labels
myPane.Title.Text = "Outdoor Irradiance";
myPane.XAxis.Title.Text = "Time";
myPane.YAxis.Title.Text = "Irradiance (W/m²)";
// Build a PointPairList with points based on Sine wave
PointPairList list = new PointPairList();
for (int i = ((last_id)-10); i < last_id; i++)
{
string mySelectQuery = "SELECT Lum_Out FROM data WHERE ID ="+i";
SqlCeCommand myCommand = new SqlCeCommand(mySelectQuery, cn);
myReader = myCommand.ExecuteReader();
myReader.Read();
double x = i * 5;
double y = Convert.ToDouble((myReader["Lum_Out"]));
list.Add(x, y);
}
// Hide the legend
myPane.Legend.IsVisible = false;
// Add a curve
LineItem curve = myPane.AddCurve("label", list, Color.Red, SymbolType.VDash);
curve.Line.Width = 1.5F;
curve.Symbol.Fill = new Fill(Color.White);
curve.Symbol.Size = 5;
// Make the XAxis start with the first label at 50
myPane.XAxis.Scale.BaseTic = 5;
// Fill the axis background with a gradient
myPane.Chart.Fill = new Fill(Color.White, Color.SteelBlue, 45.0F);
// Calculate the Axis Scale Ranges
zgc_data_lum_out.AxisChange();
// Refresh to paint the graph components
Refresh();
} |
je ne sais pas comment faire pour dire, dans ma requête que ID doit être le dernier.
Ne sachant pas si c'est claire, je vais mieux m'exprimer en disant que je ne sais pas comment dire que i = l'ID à aller chercher:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
for (int i = ((last_id)-10); i < last_id; i++)
{
string mySelectQuery = "SELECT Lum_Out FROM data WHERE ID ="+i";
SqlCeCommand myCommand = new SqlCeCommand(mySelectQuery, cn);
myReader = myCommand.ExecuteReader();
myReader.Read();
double x = i * 5;
double y = Convert.ToDouble((myReader["Lum_Out"]));
list.Add(x, y);
} |