void CreateBarChart() { int Width = 500; chart = new BarChart(Width, 600, BarChartOrientation.Vertical, BarChartStyle.Stacked); //chart.SetTitle("Vertical Stacked"); ChartAxis BottomAxis = new ChartAxis(ChartAxisType.Bottom); ChartAxis LeftAxis = new ChartAxis(ChartAxisType.Left); //LeftAxis.SetRange(0, datasets[0].Max()); if (LeftRange>0) LeftAxis.SetRange(0, LeftRange); if (BottomLabels != null) { ChartAxis BottomAxis2 = new ChartAxis(ChartAxisType.Bottom); int bottomLabelsCount = BottomLabels.Count(); for (int i = 0; i < bottomLabelsCount; i++) { string label = BottomLabels[i]; if (i % 2 != 0) { //Odd BottomAxis2.AddLabel(new ChartAxisLabel(label, (100.0f / bottomLabelsCount)*(i+0.5f))); } else { BottomAxis.AddLabel(new ChartAxisLabel(label, (100.0f / bottomLabelsCount) * (i+0.5f))); } } if (bottomLabelsCount == 1) BottomAxis2.AddLabel(new ChartAxisLabel("")); chart.AddAxis(BottomAxis); chart.AddAxis(BottomAxis2); } else chart.AddAxis(BottomAxis); //BottomAxis.AddLabel(new ChartAxisLabel( chart.AddAxis(LeftAxis); chart.SetData(datasets); chart.SetDatasetColors(new string[] { "FF0000", "00AA00" }); }
/// <summary> /// Prints the data. /// </summary> private void PrintData(params MultiRunBenchmark[] benchmarks) { DataTable data = new DataTable(); data.Columns.Add("Server"); data.Columns.Add("Run"); data.Columns.Add("Type"); data.Columns.Add("Time (seconds)"); //Populate data table foreach (var m in benchmarks) { Dictionary<string, List<int[]>> graphData = new Dictionary<string, List<int[]>>(); for (int i = 0; i < m.NumOfRuns; i++) { for (int j = 0; j < m.ServerBenchmark[i].Results.Length; j++) { BenchmarkBase b = m.ServerBenchmark[i].Results[j]; AppendDataTable(data, m.ServerBenchmark[i].ServerName, i + 1, b); } } } //Insert Graph BarChart insertBarChart = new BarChart(320, 220, BarChartOrientation.Vertical, BarChartStyle.Grouped); insertBarChart.SetTitle("Inserts"); insertBarChart.AddAxis(new ChartAxis(ChartAxisType.Bottom)); var c = new ChartAxis(ChartAxisType.Left); c.SetRange(0, 60000); insertBarChart.AddAxis(c); insertBarChart.SetData(benchmarks[0].Results .Where(b => b.Type == "Insert") .ToList() .ConvertAll<float>(b => b.Time.ElapsedMilliseconds) .ToArray()); //Print table using (GridView table = new GridView()) { table.CellPadding = 5; table.CellSpacing = 5; table.DataSource = data; table.DataBind(); StringBuilder text = new StringBuilder(); text.AppendFormat("<img src=\"{0}\" /><br/>", insertBarChart.GetUrl()); using (StringWriter wr = new StringWriter(text)) using (HtmlTextWriter htmlWr = new HtmlTextWriter(wr)) { table.RenderControl(htmlWr); this.ReportData.Replace("<%DATA%>", text.ToString()); } } }