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");
} |
Partager