protected virtual float GetMinVisibleValue(DataTable dt, int columnSeries, float[] sumStacks, int fieldOffset) { for (int i = 1; i < columnSeries; i++) { for (int j = 0; j < dt.Rows.Count; j++) { float value = float.Parse(dt.Rows[j][FIELDS[i + fieldOffset]].ToString()); sumStacks[j] += value; } } float maxValue = MyUtilities.GetMaxFloat(sumStacks); if (isUtilizationGraph) { maxValue = Math.Max(maxValue, 100); } float maxY = ClassB.FULL_SCALE(maxValue); int roundMaxY = (int)maxY; float maxYend = roundMaxY; return(maxYend * GRAPH_MIN_VALUE_FRAC); }
protected void SetColumnGraphTicks(double maxValue) { ChartArea chartArea = chart.ChartAreas[0]; if (isUtilizationGraph) { if (maxValue < 100) { maxValue = 100; } StripLine line = new StripLine(); line.Interval = 0; int maxut_val; ClassB Bcla_1 = new ClassB(GetDirectory() + userDir); maxut_val = (int)Math.Round(Convert.ToSingle(Bcla_1.get_utlimit())); line.IntervalOffset = maxut_val; // gwwd 6-26-17 was 95 line.TextAlignment = StringAlignment.Near; line.TextLineAlignment = StringAlignment.Far; line.TextOrientation = TextOrientation.Auto; line.Font = new Font("Trebuchet MS", 11.25F, FontStyle.Bold); line.ForeColor = Color.Red; line.StripWidth = 0; line.BorderColor = Color.Red; line.BorderWidth = 3; line.Text.PadLeft(50); line.Text = "Utilization limit: " + maxut_val + "%"; // gwwd 6-26-17 was 95 chartArea.AxisY.StripLines.Add(line); } if (maxValue == 0.0) { chartArea.AxisY.MajorTickMark.Interval = 50; chartArea.AxisY.MajorTickMark.Enabled = true; chartArea.AxisY.Interval = 50; chartArea.AxisY.MinorTickMark.Interval = 10; chartArea.AxisY.MinorTickMark.Enabled = true; } else { /*string val = maxValue + ""; * int numCiphers = val.Length; * int order; * if (val.IndexOf('.') > -1) { * order = ((int) (maxValue*Math.Pow(10, numCiphers - val.IndexOf('.') - 1)) / ((int)Math.Pow(10, numCiphers - 2))); * } else { * order = ((int)Math.Round(maxValue)) / ((int)Math.Pow(10, numCiphers - 1)); * } * order++; * if (order % 2 == 1) { * order++; * } * if (order % 4 == 2) { * order += 2; * } * * if (val.IndexOf('.') > -1) { * chartArea.AxisY.MajorTickMark.Interval = (((double)order) / 8) * ((int)Math.Pow(10, val.IndexOf('.')-1)); * } else { * chartArea.AxisY.MajorTickMark.Interval = (order / 4) * ((int)Math.Pow(10, numCiphers - 1)); * }*/ chartArea.AxisY.MajorTickMark.Enabled = true; chartArea.AxisY.MinorTickMark.Enabled = true; double maxY = ClassB.FULL_SCALE((float)maxValue); int roundMaxY = (int)maxY; if (roundMaxY % 5 == 0) { chartArea.AxisY.MajorTickMark.Interval = maxY / 5; } else if (roundMaxY % 4 == 0) { chartArea.AxisY.MajorTickMark.Interval = maxY / 4; } else if (roundMaxY % 3 == 0) { chartArea.AxisY.MajorTickMark.Interval = maxY / 3; } else { chartArea.AxisY.MajorTickMark.Interval = 1; } chartArea.AxisY.Maximum = maxY; int majorInt = (int)chartArea.AxisY.MajorTickMark.Interval; string majInt = majorInt + ""; int firstCipher = int.Parse(majInt.Substring(0, 1)); if (firstCipher % 4 == 0) { chartArea.AxisY.MinorTickMark.Interval = chartArea.AxisY.MajorTickMark.Interval / 4; } else if (firstCipher % 3 == 0) { chartArea.AxisY.MinorTickMark.Interval = chartArea.AxisY.MajorTickMark.Interval / 3; } else { chartArea.AxisY.MinorTickMark.Interval = chartArea.AxisY.MajorTickMark.Interval / 5; } chartArea.AxisY.Interval = chartArea.AxisY.MajorTickMark.Interval; //chartArea.AxisY.Interval = chartArea.AxisY.MajorTickMark.Interval; //chartArea.AxisY.MinorTickMark.Interval = chartArea.AxisY.MajorTickMark.Interval / 5; } }
protected void FillBarGraph() { OleDbConnection connec = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + GetDirectory() + userDir + MAIN_USER_DATABASE + ";"); OleDbCommand cmd = new OleDbCommand(graphQueryString, connec); OleDbDataAdapter adapter = new OleDbDataAdapter(cmd); { try { // fill data table connec.Open(); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { chart.Height = new Unit(600, UnitType.Pixel); int width = dt.Rows.Count * 120; width = Math.Max(width, 400); chart.Width = new Unit(width, UnitType.Pixel); } float[] barHeights = new float[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { barHeights[i] = 0; } for (int j = 0; j < dt.Rows.Count; j++) { barHeights[j] = float.Parse(dt.Rows[j][FIELDS[3]].ToString()); } float maxValue = MyUtilities.GetMaxFloat(barHeights); float maxY = ClassB.FULL_SCALE(maxValue); int roundMaxY = (int)maxY; float maxYend = roundMaxY; float minVisibleValue = maxYend * GRAPH_MIN_VALUE_FRAC; Series series = new Series(); series.ChartType = SeriesChartType.Column; series.YValueType = ChartValueType.Double; for (int j = 0; j < dt.Rows.Count; j++) { if (barHeights[j] > 0 && barHeights[j] < minVisibleValue) { barHeights[j] = minVisibleValue; } series.Points.AddY(barHeights[j]); string dataCase = dt.Rows[j][DESC[0]].ToString(); dataCase = GetGraphColHeader(dataCase); string desc = dt.Rows[j][DESC[1]].ToString(); desc = GetGraphColHeader(desc); series.Points[j].AxisLabel = dataCase + "\n" + desc; } series.IsVisibleInLegend = false; series.Name = HEADERS[3]; series.Color = ColorTranslator.FromHtml(COLORS[0]); chart.Series.Add(series); SetColumnGraphTicks(maxValue); chart.ChartAreas[0].AxisX.Interval = 1; connec.Close(); } catch (Exception) { try { connec.Close(); connec = null; } catch { } Master.ShowErrorMessage(); } } }