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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| public void showGraph(Chart chartGraph, string typeGraph, ArrayList pointX, ArrayList pointY, string currentText, string segmentInt, string axisInt)
{
//Titre du graphique
chartGraph.Titles[0].Text = currentText;
// Set Title font
chartGraph.Titles[0].Font = new Font("Times New Roman", 18, FontStyle.Bold);
// Set Title color
chartGraph.Titles[0].Color = Color.Blue;
// Set manual minimum and maximum values.
chartGraph.ChartAreas["Default"].AxisY.Minimum = info.getMinMaxValue(pointY)[0] -
Math.Round((info.getMinMaxValue(pointY)[0] * 0.1), 2);
//}
//on ne traite que les valeurs supérieurs ou egales à la valeur minimale
//excluant la valeur max 0 et la valeur min 0
if (info.getMinMaxValue(pointY)[0] <= info.getMinMaxValue(pointY)[1] &&
(info.getMinMaxValue(pointY)[1] != 0 && info.getMinMaxValue(pointY)[0] != 0))
{
chartGraph.ChartAreas["Default"].AxisY.Maximum = info.getMinMaxValue(pointY)[1] +
Math.Round((info.getMinMaxValue(pointY)[1] * 0.1), 2);
}
switch (typeGraph)
{
case "point":
// Set interval of X axis to 1 week, with an offset of 1 day
chartGraph.ChartAreas["Default"].AxisX.Interval = 3;
chartGraph.ChartAreas["Default"].AxisX.IntervalType = DateTimeIntervalType.Weeks;
chartGraph.ChartAreas["Default"].AxisX.IntervalOffset = 21;
chartGraph.ChartAreas["Default"].AxisX.IntervalOffsetType = DateTimeIntervalType.Days;
chartGraph.Series["Series1"].Type = SeriesChartType.Point;
chartGraph.Series["Series1"].MarkerStyle = MarkerStyle.Circle;
//chartGraph.Series["Series1"].XValueType = ChartValueTypes.DateTime;
chartGraph.Series["Series1"].Points.DataBindXY(pointX, "DateTime", pointY, "Valeur");
chartGraph.Series["Series1"].XValueType = ChartValueTypes.DateTime;
// chartGraph.ChartAreas[0].AxisX.LabelStyle.Format = "yyyy-MM-dd HH:mm";
chartGraph.ChartAreas["Default"].AxisX.LabelStyle.Format = "g";
break;
case "diagram":
//chartGraph.Series["Series1"].Type = SeriesChartType.Column;
chartGraph.Series["Series1"].Points.DataBindY(pointY);
HistogramChartHelper helper = new HistogramChartHelper();
// Show the percent frequency on the right Y axis.
helper.ShowPercentOnSecondaryYAxis = false;//true
if (!cbbSegmentInterval.Text.Equals("") &&
!cbbSegmentInterval.Text.Equals("Select Interval"))
{
// Specify number of segment intervals
helper.SegmentIntervalNumber = int.Parse(cbbSegmentInterval.Text);
}
else
{
helper.SegmentIntervalNumber = 10;
}
// Create histogram series
try
{
helper.CreateHistogram(chartGraph, "Series1", "Histogram");
SetHistogramLayout(chartGraph, "Series1", "Histogram");
// Reset y-axis min/max
chartGraph.ChartAreas[0].AxisY.Minimum = double.NaN; ;
chartGraph.ChartAreas[0].AxisY.Maximum = double.NaN;
// Get the max x-value on Histogram
DataPoint dpMax = chartGraph.Series["Histogram"].Points.FindMaxValue("X");
// Get before and after (rounding) value
double maxXBefore = dpMax.XValue;
double maxXAfter = Math.Ceiling(dpMax.XValue);
// Set x-axis' max to rounded value
chartGraph.ChartAreas[0].AxisX.Maximum = maxXAfter;
//MessageBox.Show(string.Format("Before: {0}\nAfter: {1}", maxXBefore, maxXAfter));
}
catch (ArgumentOutOfRangeException)
{
}
catch (InvalidOperationException)
{
}
//set interval
if (!cbbAxisInterval.Text.Equals("") &&
!cbbAxisInterval.Text.Equals("Select Axis"))
{
chartGraph.ChartAreas[0].AxisX.Interval = int.Parse(cbbAxisInterval.Text);
}
else
{
chartGraph.ChartAreas[0].AxisX.Interval = 1;
}
//chartGraph.Titles[0].Text = Regex.Split(chartGraph.Titles[0].Text, "\r\n")[1];
chartGraph.Titles[0].Visible = false;
break;
}
//// Set Border Color
chartGraph.ChartAreas["Default"].BorderColor = Color.Black;
//// Set Border Style
chartGraph.ChartAreas["Default"].BorderStyle = ChartDashStyle.Solid;
// enable axis line
chartGraph.ChartAreas["Default"].AxisX.MajorGrid.Enabled = false;
//Legend
chartGraph.Legends["Default"].Enabled = false;
//chartGraph.Serializer.Content = SerializationContent.All;
//chartGraph.Serializer.Save(@"c:\chart.xml");
} |
Partager