Hello,
You can change the number of days in the line
int NbreGraphes =23;
Thanks
protected void Button4_Click(object sender, EventArgs e)
{
Chart c = new Chart();
c.Height = 900;
c.Width = 1300;
c.BackColor = Color.FromArgb(250, 250, 250);
c.Titles.Add(new Title());
c.Titles[0].Text = "ASPOSE : Line, Hours Format Axis X";
c.ChartAreaLayout = LayoutType.Row;
ChartArea a = null;
int NbreGraphes =23;
for (int cnt = 0; cnt < NbreGraphes-1; cnt++)
{
a = new ChartArea(c);
c.ChartAreas.Add(a);
}
for (int x = 0; x < NbreGraphes; x++)
{
c.ChartAreas[x].AxisX.IsAutoCalc = false;
c.ChartAreas[x].AxisX.DefaultLabel.FontAngle = -90;
c.ChartAreas[x].AxisX.DefaultLabel.Font = new Font("Arial", 8);
c.ChartAreas[x].AxisX.Minimum = (new DateTime(2007, 8, 1 , 8, 0, 0).AddDays(x)).ToOADate();
c.ChartAreas[x].AxisX.Maximum = (new DateTime(2007, 8, 1 , 18, 0, 0).AddDays(x)).ToOADate();
// c.ChartAreas[x].AxisX.DefaultLabel.Format = "hh:mm";
c.ChartAreas[x].AxisX.DefaultLabel.Format = "t";
c.ChartAreas[x].AxisX.IntervalType = IntervalType.DateTime;
c.ChartAreas[x].AxisX.DateTimeIntervalType = DateTimeIntervalType.Hours;
c.ChartAreas[x].AxisX.Interval = 1;
c.ChartAreas[x].Name = string.Format("Area{0}", x + 1);
c.ChartAreas[x].IsMargin = false;
c.ChartAreas[x].AxisAreaPosition = new System.Drawing.RectangleF(70 + x * (1200 / NbreGraphes), 100, (1200 / NbreGraphes)-5, 600);
c.ChartAreas[x].AxisY.IsAutoCalc = false;
c.ChartAreas[x].AxisY.Interval = 20000;
c.ChartAreas[x].AxisY.Minimum = 0;
c.ChartAreas[x].AxisY.Maximum = 100000;
c.ChartAreas[x].AxisY.IntervalType = IntervalType.Int;
c.ChartAreas[x].BackColor = Color.White;
}
for (int x = 0; x < NbreGraphes; x++)
{
Series s0 = new Series();
s0.ChartArea = string.Format("Area{0}", x+1);
s0.ChartType = ChartType.Line;
s0.Name = "Rapidité d'accès au réseau interne";
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 8, 0, 0).AddDays(x)).ToOADate(), 43000));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 8, 30, 0).AddDays(x)).ToOADate(), 29140));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 9, 4, 0).AddDays(x)).ToOADate(), 14790));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 9, 33, 0).AddDays(x)).ToOADate(), 36140));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 10, 3, 0).AddDays(x)).ToOADate(), 29480));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 10, 34, 0).AddDays(x)).ToOADate(), 31610));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 11, 3, 0).AddDays(x)).ToOADate(), 40230));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 11, 34, 0).AddDays(x)).ToOADate(), 36310));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 12, 0, 0).AddDays(x)).ToOADate(), 36420));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 12, 30, 0).AddDays(x)).ToOADate(), 20370));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 13, 30, 0).AddDays(x)).ToOADate(), 49530));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 15, 4, 0).AddDays(x)).ToOADate(), 15150));
s0.DataPoints.Add(new DataPoint("point", (new DateTime(2007, 8, 1, 15, 34, 0).AddDays(x)).ToOADate(), 16730));
//s0.IsPrimaryAxisX = false;
//s0.IsPrimaryAxisY = false;
c.SeriesCollection.Add(s0);
}
for (int x = 1; x < NbreGraphes; x++)
{
c.ChartAreas[x].AxisY.AxisLabels.Clear();
c.ChartAreas[x].AxisY.MajorTickMark.IsVisible = false;
c.ChartAreas[x].AxisY.MinorTickMark.IsVisible = false;
}
for (int x = 0; x < NbreGraphes; x++)
{
AxisLabel label = new AxisLabel();
label.IsCustomLabelGridVisible = true;
label.Color = Color.Black;
label.Text = string.Format("{0}",(x + 1));
label.FromValue = (new DateTime(2007, 8, 1 , 8, 0, 0).AddDays(x)).ToOADate();
label.ToValue = (new DateTime(2007, 8, 1 , 18, 0, 0).AddDays(x)).ToOADate();
label.Font = new Font("Arial", 10);
c.ChartAreas[x].AxisX.CustomLabels.Add(label);
if (x == 2)
{
LegendBox legendBox = c.ChartAreas[x ].LegendBox;
legendBox.IsVisible = true;
// Setting gradient background color
legendBox.GradientType = GradientType.HorizontalCenter;
legendBox.GradientBackColor = Color.Cornsilk;
// Setting border
legendBox.BorderColor = Color.Bisque;
legendBox.BorderWidth = 3;
// Setting position
legendBox.LegendPositionType = LegendPositionType.Right;
// Setting layout
// legendBox.LayoutType = LayoutType.TableVertical;
legendBox.LayoutType = LayoutType.Row;
// Setting type
legendBox.LegendBoxType = LegendBoxType.OutsideChartArea;
// Setting items type
legendBox.LegendItemsType = LegendItemsType.BySeries;
legendBox.LegendPositionType = LegendPositionType.Custom;
legendBox.Font = new Font("Arial", 12);
legendBox.Position = new RectangleF(20, 45, 1270, 35);
}
else
{
c.ChartAreas[x].LegendBox.IsVisible = false;
}
c.ChartAreas[x].AxisX.IsAutoCalc = false;
}
MemoryStream ms = new MemoryStream();
c.Save(ms, ImageFormat.Png);
Response.Clear();
Response.ContentType = "image/png";
Response.OutputStream.Write(ms.ToArray(), 0, (int)ms.Length);
}