private void BindDataForChart(GraphPane myPane) { //绑定数据 string[] dateTime = new string[EmployeeComeAndLeaveList.Count]; double[] comeCount = new double[EmployeeComeAndLeaveList.Count]; double[] leaveCount = new double[EmployeeComeAndLeaveList.Count]; for (int i = 0; i < EmployeeComeAndLeaveList.Count; i++) { dateTime[i] = EmployeeComeAndLeaveList[i].Year + "/" + EmployeeComeAndLeaveList[i].Month; comeCount[i] = EmployeeComeAndLeaveList[i].Entry; leaveCount[i] = EmployeeComeAndLeaveList[i].Dimission; } myPane.AddBar("进入人数", null, comeCount, Color.DimGray); myPane.AddBar("离开人数", null, leaveCount, Color.DarkSalmon); myPane.XAxis.MajorTic.IsBetweenLabels = true; myPane.XAxis.Scale.TextLabels = dateTime; myPane.XAxis.Type = AxisType.Text; myPane.BarSettings.Type = BarType.Cluster; myPane.BarSettings.Base = BarBase.X; }
/// <summary> /// 柱形图表 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button12_Click(object sender, EventArgs e) { myPane = zedGraphControl1.GraphPane; double[] x = { 2, 4, 6, 8, 10, 12 }; //定义变量存储数据的X坐标 double[] y = { 100, 115, 75, 22, 98, 40 }; //定义变量存储数据的Y坐标 BarItem myBar = myPane.AddBar("Curve 1", x, y, Color.Red); // BarItem它的基类ZedGraph.CurveItem里包含了Pane上单个曲线图表的数据和方法。 //它实现了图表的属性设置,myPane.AddBar方法中的第一个参数为柱形图的注释,第二三个参数分别是数据的X,Y坐标, //最后一个参数为柱形图的颜色。 myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red); //设置柱形图颜色,两边为Red,中间为White。 //myPane.BarSettings.Base = BarBase.Y; //以Y轴为基轴 myPane.BarSettings.Base = BarBase.X; //以X轴为基轴 myBar = myPane.AddBar("Curve 2", null, y, Color.Blue); myBar.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue); myPane.BarSettings.Type = BarType.Stack; //BarType是一个枚举,共有六项, //分别为Cluster、ClusterHiLow、Overlay、SortedOverlay、Stack和PercentStack, //Cluster和ClusterHiLow是让多个同一个基类Bar依次排开,Cluster还可以使用来自IPointList的“Z”的值来定义每一个Bar的底部, //Overlay和SortedOverlay就是柱形按坐标相互覆盖。 //不同之处在于Overlay是按照哪个先画哪个在前的原则(注意这里不是按后画把先画的柱形覆盖的原则,而是正好相反按先画在前原则)。 //SortedOverlay是按位标的大小,按小的位标在前,大的位标在后的原则来绘图的, 最后的两个Stack和PercentStack就是按先前的位标依次累积上升。 myPane.Chart.Fill = new Fill(Color.White, Color.SteelBlue, 45.0f); myPane.AxisChange(this.CreateGraphics()); zedGraphControl1.Refresh(); }
//Make diagram in ZedGraph public GraphPane HistogramDiagramRGB(List <PointPairList> histogramPoint, int width, int height) { GraphPane graphPane = new GraphPane(); graphPane.Title.Text = ""; //Name of diagram graphPane.Rect = new Rectangle(0, 0, width, height); //Set up Ox graphPane.XAxis.Title.Text = @"Giá trị màu"; graphPane.XAxis.Scale.Min = 0; //Min = 0 graphPane.XAxis.Scale.Max = 255; graphPane.XAxis.Scale.MajorStep = 5; graphPane.XAxis.Scale.MinorStep = 1; //Set up Oy graphPane.YAxis.Title.Text = @"Số điểm ảnh"; graphPane.YAxis.Scale.Min = 0; //Min = 0 graphPane.YAxis.Scale.Max = 120000; graphPane.YAxis.Scale.MajorStep = 10000; graphPane.YAxis.Scale.MinorStep = 5; //Perform graphPane.AddBar("", histogramPoint[0], Color.Red); graphPane.AddBar("", histogramPoint[1], Color.Green); graphPane.AddBar("", histogramPoint[2], Color.Blue); return(graphPane); }
public void UpdateTestExecutionsChart(string version, string branch, string node, string service, string testID, string testName, DateTime from, DateTime to) { GraphPane myPane = zedGraphControl_TestPassFailByExecution.GraphPane; myPane.CurveList.Clear(); zedGraphControl_TestPassFailByExecution.Refresh(); Dictionary <DateTime, string> ret = m_MySql.GetTestCaseExecutionsByDate(version, branch, node, service, testID, from, to); if (ret.Count == 0) { return; } List <double> values_pass = new List <double>(); List <double> values_fail = new List <double>(); List <string> dates = new List <string>(); foreach (DateTime rec in ret.Keys) { if (ret[rec] == "PASS") { values_pass.Add(1); values_fail.Add(0); } else { values_pass.Add(0); values_fail.Add(-1); } dates.Add(rec.ToShortDateString()); } myPane.BarSettings.Type = BarType.Stack; myPane.Title.Text = "[" + testName + "] test status per execution"; myPane.Fill = new Fill(Color.Snow, Color.LightGoldenrodYellow, Color.Snow); myPane.XAxis.Title.Text = "Execution (days)"; myPane.XAxis.Type = AxisType.Text; myPane.XAxis.Scale.Format = "dd.MM.yy"; myPane.XAxis.Scale.FontSpec.Angle = 45; myPane.XAxis.MajorGrid.IsVisible = true; myPane.XAxis.Scale.TextLabels = dates.ToArray(); myPane.YAxis.Title.Text = "Status (PASSED/FAILED)"; myPane.YAxis.MajorGrid.IsVisible = true; myPane.YAxis.Scale.Min = -2; myPane.YAxis.Scale.Max = 2; myPane.YAxis.Scale.MajorStep = 1; BarItem passedBar = myPane.AddBar("Passed", null, values_pass.ToArray(), Color.Green); BarItem failedBar = myPane.AddBar("Failed", null, values_fail.ToArray(), Color.Red); zedGraphControl_TestPassFailByExecution.AxisChange(); zedGraphControl_TestPassFailByExecution.Refresh(); }
public BarChartSampleDemo() : base("Code Project Bar Chart Sample", "Bar Chart Sample", DemoType.Tutorial) { GraphPane myPane = base.GraphPane; // Set the titles and axis labels myPane.Title.Text = "My Test Bar Graph"; myPane.XAxis.Title.Text = "Label"; myPane.YAxis.Title.Text = "My Y Axis"; // Make up some random data points string[] labels = { "Panther", "Lion", "Cheetah", "Cougar", "Tiger", "Leopard" }; double[] y = { 100, 115, 75, 22, 98, 40 }; double[] y2 = { 90, 100, 95, 35, 80, 35 }; double[] y3 = { 80, 110, 65, 15, 54, 67 }; double[] y4 = { 120, 125, 100, 40, 105, 75 }; // Generate a red bar with "Curve 1" in the legend BarItem myBar = myPane.AddBar("Curve 1", null, y, Color.Red); myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red); // Generate a blue bar with "Curve 2" in the legend myBar = myPane.AddBar("Curve 2", null, y2, Color.Blue); myBar.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue); // Generate a green bar with "Curve 3" in the legend myBar = myPane.AddBar("Curve 3", null, y3, Color.Green); myBar.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green); // Generate a black line with "Curve 4" in the legend LineItem myCurve = myPane.AddCurve("Curve 4", null, y4, Color.Black, SymbolType.Circle); myCurve.Line.Fill = new Fill(Color.White, Color.LightSkyBlue, -45F); // Fix up the curve attributes a little myCurve.Symbol.Size = 8.0F; myCurve.Symbol.Fill = new Fill(Color.White); myCurve.Line.Width = 2.0F; // Draw the X tics between the labels instead of at the labels myPane.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels myPane.XAxis.Scale.TextLabels = labels; // Set the XAxis to Text type myPane.XAxis.Type = AxisType.Text; // Fill the axis area with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); // Fill the pane area with a solid color myPane.Fill = new Fill(Color.FromArgb(250, 250, 255)); base.ZedGraphControl.AxisChange(); }
public StackedBarsWithLabelsDemo() : base("A stacked bar graph that includes a text label inside each bar", "Stacked Bars with Labels Demo", DemoType.Bar) { GraphPane myPane = base.GraphPane; // Set the title and axis labels myPane.Title.Text = "Stacked Bars with Value Labels Inside Each Bar"; myPane.XAxis.Title.Text = "Position Number"; myPane.YAxis.Title.Text = "Some Random Thing"; // Create points for three BarItems PointPairList list1 = new PointPairList(); PointPairList list2 = new PointPairList(); PointPairList list3 = new PointPairList(); // Use random data values Random rand = new Random(); for (int i = 1; i < 5; i++) { double y = (double)i; double x1 = 100.0 + rand.NextDouble() * 100.0; double x2 = 100.0 + rand.NextDouble() * 100.0; double x3 = 100.0 + rand.NextDouble() * 100.0; list1.Add(x1, y); list2.Add(x2, y); list3.Add(x3, y); } // Create the three BarItems, change the fill properties so the angle is at 90 // degrees for horizontal bars BarItem bar1 = myPane.AddBar("Bar 1", list1, Color.Red); bar1.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red, 90); BarItem bar2 = myPane.AddBar("Bar 2", list2, Color.Blue); bar2.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue, 90); BarItem bar3 = myPane.AddBar("Bar 3", list3, Color.Green); bar3.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green, 90); // Set BarBase to the YAxis for horizontal bars myPane.BarSettings.Base = BarBase.Y; // Make the bars stack instead of cluster myPane.BarSettings.Type = BarType.Stack; // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 45.0F); base.ZedGraphControl.AxisChange(); // Create TextObj's to provide labels for each bar CreateBarLabels(myPane, true, "N0"); }
/// <summary> /// Создать столбики по данным /// </summary> /// <param name="pane">Панель, куда добавляются столбцы</param> /// <param name="XValues">Координаты по оси X</param> /// <param name="YValues1">Данные по оси Y для первого набора столбцов</param> /// <param name="YValues2">Данные по оси Y для второго набора столбцов</param> /// <param name="YValues3">Данные по оси Y для третьего набора столбцов</param> private static void CreateBars(GraphPane pane, double[] XValues, double[] YValues1, double[] YValues2, double[] YValues3) { pane.CurveList.Clear(); // Создадим три гистограммы pane.AddBar("", XValues, YValues1, Color.Blue); pane.AddBar("", XValues, YValues2, Color.Red); pane.AddBar("", XValues, YValues3, Color.Yellow); }
public HorizontalBarSampleDemo() : base("Code Project Horizontal Bar Chart Sample", "Horizontal Bar Sample", DemoType.Tutorial) { GraphPane myPane = base.GraphPane; // Set the title and axis labels myPane.Title.Text = "A Horizontal Percent Stack Graph"; myPane.XAxis.Title.Text = "Stuff"; myPane.YAxis.Title.Text = ""; // Enter some random data values double[] y = { 100, 115, 15, 22, 98 }; double[] y2 = { 90, 60, 95, 35, 30 }; double[] y3 = { 20, 40, 105, 15, 30 }; // Generate a red bar with "Nina" in the legend BarItem myCurve = myPane.AddBar("Nina", y, null, Color.Red); myCurve.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red, 90F); // Generate a blue bar with "Pinta" in the legend myCurve = myPane.AddBar("Pinta", y2, null, Color.Blue); myCurve.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue, 90F); // Generate a green bar with "Santa Maria" in the legend myCurve = myPane.AddBar("Santa Maria", y3, null, Color.Green); myCurve.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green, 90F); // Draw the Y tics between the labels instead of at the labels myPane.YAxis.MajorTic.IsBetweenLabels = true; // Set the YAxis to text type myPane.YAxis.Type = AxisType.Text; string[] labels = { "Australia", "Africa", "America", "Asia", "Antartica" }; myPane.YAxis.Scale.TextLabels = labels; myPane.XAxis.Scale.Max = 110; // Make the bars horizontal by setting bar base axis to Y myPane.BarSettings.Base = BarBase.Y; // Make the bars percent stack type myPane.BarSettings.Type = BarType.PercentStack; // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); // Fill the legend background with a color gradient myPane.Legend.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 250), 90F); // Fill the pane background with a solid color myPane.Fill = new Fill(Color.FromArgb(250, 250, 255)); base.ZedGraphControl.AxisChange(); }
// Build the Chart private void CreateGraph_Chart(ZedGraphControl zg1) { // get a reference to the GraphPane GraphPane myPane = zg1.GraphPane; // Make up some random data points string[] labels = { "Panther", "Lion", "Cheetah", "Cougar", "Tiger", "Leopard" }; double[] y = { 100, 115, 75, 22, 98, 40 }; double[] y2 = { 90, 100, 95, 35, 80, 35 }; double[] y3 = { 80, 110, 65, 15, 54, 67 }; double[] y4 = { 120, 125, 100, 40, 105, 75 }; // Generate a red bar with "Curve 1" in the legend BarItem myBar = myPane.AddBar("Curve 1", null, y, Color.Red); myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red); // Generate a blue bar with "Curve 2" in the legend myBar = myPane.AddBar("Curve 2", null, y2, Color.Blue); myBar.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue); // Generate a green bar with "Curve 3" in the legend myBar = myPane.AddBar("Curve 3", null, y3, Color.Green); myBar.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green); // Generate a black line with "Curve 4" in the legend LineItem myCurve = myPane.AddCurve("Curve 4", null, y4, Color.Black, SymbolType.Circle); myCurve.Line.Fill = new Fill(Color.White, Color.LightSkyBlue, -45F); // Fix up the curve attributes a little myCurve.Symbol.Size = 8.0F; myCurve.Symbol.Fill = new Fill(Color.White); myCurve.Line.Width = 2.0F; // Draw the X tics between the labels instead of // at the labels myPane.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels myPane.XAxis.Scale.TextLabels = labels; // Set the XAxis to Text type myPane.XAxis.Type = AxisType.Text; // Fill the Axis and Pane backgrounds myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F); myPane.Fill = new Fill(Color.FromArgb(250, 250, 255)); // Tell ZedGraph to refigure the // axes since the data have changed zg1.AxisChange(); }
public static void CreateExtremeEventPlot(ZedGraphControl zgc) { // Display point values zgc.PointValueFormat = "F2"; zgc.IsShowPointValues = true; // Get a reference to the GraphPane GraphPane myPane = zgc.GraphPane; SetCommonProperties(myPane); myPane.Legend.IsVisible = true; /* * myPane.Legend.FontSpec.Size = 10; * myPane.Title.FontSpec.Size = 12; * myPane.XAxis.Title.FontSpec.Size = 12; * myPane.YAxis.Title.FontSpec.Size = 12; */ // Set the graph's titles myPane.Title.Text = "Extreme Event Rainfall / Runoff Depth"; myPane.XAxis.Title.Text = ""; // "Return Period (years)"; myPane.XAxis.Type = AxisType.Text; myPane.YAxis.Title.Text = "Depth (inches)"; myPane.XAxis.Scale.TextLabels = returnPeriodLabels1; myPane.XAxis.MajorTic.Size = 0; myPane.XAxis.MajorGrid.IsVisible = false; // Create data arrays Xevent.extremeRainfallList = new PointPairList(); Xevent.extremeRunoffList = new PointPairList(); Xevent.baseExtremeRainfallList = new PointPairList(); Xevent.baseExtremeRunoffList = new PointPairList(); // Add bars for rainfall and runoff BarItem myBar1 = myPane.AddBar( "Rainfall", Xevent.extremeRainfallList, colors[2]); BarItem myBar2 = myPane.AddBar( "Runoff", Xevent.extremeRunoffList, colors[0]); baselineBar1 = myPane.AddBar( "Base Rainfall", Xevent.baseExtremeRainfallList, colors[3]); baselineBar2 = myPane.AddBar( "Base Runoff", Xevent.baseExtremeRunoffList, colors[1]); // Overlay the bars myPane.BarSettings.Type = BarType.SortedOverlay; baselineBar1.Label.IsVisible = false; baselineBar2.Label.IsVisible = false; // Tell ZedGraph to refigure the axes since the data have changed zgc.AxisChange(); }
/// <summary> /// This method is where you generate your graph. /// </summary> /// <param name="masterPane">You are provided with a MasterPane instance that /// contains one GraphPane by default (accessible via masterPane[0]).</param> /// <param name="g">A graphics instance so you can easily make the call to AxisChange()</param> private void OnRenderGraph1(ZedGraphWeb zgw, Graphics g, MasterPane masterPane) { // Get the GraphPane so we can work with it GraphPane myPane = masterPane[0]; // Set the title and axis labels myPane.Title.Text = "Cat Stats"; myPane.YAxis.Title.Text = "Big Cats"; myPane.XAxis.Title.Text = "Population"; // Make up some data points string[] labels = { "Panther", "Lion", "Cheetah", "Cougar", "Tiger", "Leopard" }; double[] x = { 100, 115, 75, 22, 98, 40 }; double[] x2 = { 120, 175, 95, 57, 113, 110 }; double[] x3 = { 204, 192, 119, 80, 134, 156 }; // Generate a red bar with "Curve 1" in the legend BarItem myCurve = myPane.AddBar("Here", x, null, Color.Red); // Fill the bar with a red-white-red color gradient for a 3d look myCurve.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red, 90f); // Generate a blue bar with "Curve 2" in the legend myCurve = myPane.AddBar("There", x2, null, Color.Blue); // Fill the bar with a Blue-white-Blue color gradient for a 3d look myCurve.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue, 90f); // Generate a green bar with "Curve 3" in the legend myCurve = myPane.AddBar("Elsewhere", x3, null, Color.Green); // Fill the bar with a Green-white-Green color gradient for a 3d look myCurve.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green, 90f); // Draw the Y tics between the labels instead of at the labels myPane.YAxis.MajorTic.IsBetweenLabels = true; // Set the YAxis labels myPane.YAxis.Scale.TextLabels = labels; // Set the YAxis to Text type myPane.YAxis.Type = AxisType.Text; // Set the bar type to stack, which stacks the bars by automatically accumulating the values myPane.BarSettings.Type = BarType.Stack; // Make the bars horizontal by setting the BarBase to "Y" myPane.BarSettings.Base = BarBase.Y; // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 45.0F); masterPane.AxisChange(g); }
public void UpdateTestsSetsChart(string version, string branch, string node, string service, DateTime from, DateTime to) { GraphPane myPane = zedGraphControl_TestSets.GraphPane; myPane.CurveList.Clear(); zedGraphControl_TestSets.Refresh(); Dictionary <DateTime, List <double> > ret = m_MySql.GetPassFailTestsCountByDate(version, branch, node, service, from, to); label_TotalExecutionsCount.Text = ret.Count.ToString(); if (ret.Count == 0) { return; } List <double> passed = new List <double>(); List <double> failed = new List <double>(); List <string> dates = new List <string>(); foreach (DateTime rec in ret.Keys) { dates.Add(rec.ToShortDateString()); passed.Add(ret[rec][0]); failed.Add(ret[rec][1]); } myPane.BarSettings.Type = BarType.Stack; myPane.Title.Text = "Sanity tests status per execution"; myPane.Fill = new Fill(Color.Snow, Color.LightGoldenrodYellow, Color.Snow); zedGraphControl_TestSets.IsShowPointValues = true; zedGraphControl_TestSets.PointValueFormat = "0"; myPane.XAxis.Title.Text = "Execution (days)"; myPane.XAxis.Type = AxisType.Text; myPane.XAxis.Scale.Format = "dd.MM.yy"; myPane.XAxis.Scale.FontSpec.Angle = 45; myPane.XAxis.MajorGrid.IsVisible = true; myPane.XAxis.Scale.TextLabels = dates.ToArray(); myPane.YAxis.Title.Text = "Count of pass and fail tests"; myPane.YAxis.MajorGrid.IsVisible = true; myPane.YAxis.MinorGrid.IsVisible = true; BarItem passedBar = myPane.AddBar("Passed", null, passed.ToArray(), Color.Green); BarItem failedBar = myPane.AddBar("Failed", null, failed.ToArray(), Color.Red); passedBar.IsVisible = true; failedBar.IsVisible = true; zedGraphControl_TestSets.AxisChange(); zedGraphControl_TestSets.Refresh(); }
public HorizontalBarsWithLabelsDemo() : base("A bar graph that includes a text label next to each bar", "Horizontal Bars with Labels Demo", DemoType.Bar) { GraphPane myPane = base.GraphPane; // Set the title and axis labels myPane.Title.Text = "Horizontal Bars with Value Labels Above Each Bar"; myPane.XAxis.Title.Text = "Some Random Thing"; myPane.YAxis.Title.Text = "Position Number"; // Create data points for three BarItems using Random data PointPairList list = new PointPairList(); PointPairList list2 = new PointPairList(); PointPairList list3 = new PointPairList(); Random rand = new Random(); for (int i = 0; i < 4; i++) { double y = (double)i + 5; double x = rand.NextDouble() * 1000; double x2 = rand.NextDouble() * 1000; double x3 = rand.NextDouble() * 1000; list.Add(x, y); list2.Add(x2, y); list3.Add(x3, y); } // Create the three BarItems, change the fill properties so the angle is at 90 // degrees for horizontal bars BarItem myCurve = myPane.AddBar("curve 1", list, Color.Blue); myCurve.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue, 90); BarItem myCurve2 = myPane.AddBar("curve 2", list2, Color.Red); myCurve2.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red, 90); BarItem myCurve3 = myPane.AddBar("curve 3", list3, Color.Green); myCurve3.Bar.Fill = new Fill(Color.Green, Color.White, Color.Green, 90); // Set BarBase to the YAxis for horizontal bars myPane.BarSettings.Base = BarBase.Y; // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 45.0F); base.ZedGraphControl.AxisChange(); // Create TextObj's to provide labels for each bar CreateBarLabels(myPane, false, "N0"); }
/// <summary> /// Построение гистограммы /// </summary> /// <param name="text">Подпись гистограммы</param> public void MakeGraph_Gistogramma(String text) { /////////////////////////////////////////////// // Версия с нулевыми столбиками int Gist_min_number = gisto.Gistogramma_number[0]; int Gist_max_number = gisto.Gistogramma_number[0]; for (int i = 0; i < gisto.turr; i++) { if (Gist_min_number > gisto.Gistogramma_number[i]) { Gist_min_number = gisto.Gistogramma_number[i]; } if (Gist_max_number < gisto.Gistogramma_number[i]) { Gist_max_number = gisto.Gistogramma_number[i]; } } string[] names = new string[Gist_max_number - Gist_min_number + 1]; // Высота столбиков double[] values = new double[Gist_max_number - Gist_min_number + 1]; // Заполним данные for (int i = Gist_min_number; i < Gist_max_number + 1; i++) { names[i - Gist_min_number] = string.Format("{0}-{1}", i * gisto.Shag_mod - gisto.Shag_mod, i * gisto.Shag_mod); values[i - Gist_min_number] = gisto.Gistogramma[i] * 100 / gisto.GIST_SUM; } StreamWriter writer = new StreamWriter("Гистограммы данные.txt"); for (int i = Gist_min_number; i < Gist_max_number + 1; i++) { writer.WriteLine(names[i - Gist_min_number] + "\t" + Math.Round(Convert.ToDouble(gisto.Gistogramma[i]) * 100.0 / Convert.ToDouble(gisto.GIST_SUM), 3)); } writer.Close(); BarItem curve = pane.AddBar(text, null, values, Color.Blue); // Настроим ось X так, чтобы она отображала текстовые данные pane.XAxis.Type = AxisType.Text; // Уставим для оси наши подписи pane.XAxis.Scale.TextLabels = names; }
private void DrawGraph() { // Получим панель для рисования GraphPane pane = zedGraph.GraphPane; // Очистим список кривых на тот случай, если до этого сигналы уже были нарисованы pane.CurveList.Clear(); int itemscount = 5; Random rnd = new Random(); // Высоты столбиков double[] YValues1 = new double[itemscount]; double[] YValues2 = new double[itemscount]; double[] YValues3 = new double[itemscount]; double[] XValues = new double[itemscount]; // Заполним данные for (int i = 0; i < itemscount; i++) { XValues[i] = i + 1; YValues1[i] = rnd.NextDouble(); YValues2[i] = rnd.NextDouble(); YValues3[i] = rnd.NextDouble(); } // Создадим три гистограммы // Так как для всех гистограмм мы передаем одинаковые массивы координат по X, // то столбики будут группироваться в кластеры в этих точках. BarItem bar1 = pane.AddBar("Values1", XValues, YValues1, Color.Blue); BarItem bar2 = pane.AddBar("Values2", XValues, YValues2, Color.Red); BarItem bar3 = pane.AddBar("Values3", XValues, YValues3, Color.Yellow); // !!! Расстояния между столбиками в кластере (группами столбиков) pane.BarSettings.MinBarGap = 0.0f; // !!! Увеличим расстояние между кластерами в 2.5 раза pane.BarSettings.MinClusterGap = 2.5f; // Вызываем метод AxisChange (), чтобы обновить данные об осях. zedGraph.AxisChange(); // Обновляем график zedGraph.Invalidate(); }
public VerticalBarsWithLabelsDemo() : base("A bar graph that includes a text label above each bar", "Vertical Bars with Labels Demo", DemoType.Bar) { GraphPane myPane = base.GraphPane; // Set the title and axis labels myPane.Title.Text = "Vertical Bars with Value Labels Above Each Bar"; myPane.XAxis.Title.Text = "Position Number"; myPane.YAxis.Title.Text = "Some Random Thing"; PointPairList list = new PointPairList(); PointPairList list2 = new PointPairList(); PointPairList list3 = new PointPairList(); Random rand = new Random(); // Generate random data for three curves for (int i = 0; i < 5; i++) { double x = (double)i; double y = rand.NextDouble() * 1000; double y2 = rand.NextDouble() * 1000; double y3 = rand.NextDouble() * 1000; list.Add(x, y); list2.Add(x, y2); list3.Add(x, y3); } // create the curves BarItem myCurve = myPane.AddBar("curve 1", list, Color.Blue); BarItem myCurve2 = myPane.AddBar("curve 2", list2, Color.Red); BarItem myCurve3 = myPane.AddBar("curve 3", list3, Color.Green); // Fill the axis background with a color gradient myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 45.0F); base.ZedGraphControl.AxisChange(); // expand the range of the Y axis slightly to accommodate the labels myPane.YAxis.Scale.Max += myPane.YAxis.Scale.MajorStep; // Create TextObj's to provide labels for each bar BarItem.CreateBarLabels(myPane, false, "f0"); // Create a label for each bar // CreateBarLabels( myPane, false, "N0" ); }
private void CreateBarChart() { GraphPane pane = zedGraphControl.GraphPane; pane.CurveList.Clear(); List <double> XValues = new List <double>(); List <double> YValues = new List <double>(); int lastNode = tree[tree.Count - 1].Item1; int count = 1; int quantity = 0; for (int i = 2; i < tree.Count; i++) { if (tree[i].Item1 == count) { quantity++; } else { XValues.Add((double)count); YValues.Add((double)quantity); count++; quantity = 0; i--; } } BarItem bar = pane.AddBar("Node quantities", XValues.ToArray(), YValues.ToArray(), Color.Blue); pane.BarSettings.MinClusterGap = 2.5f; zedGraphControl.AxisChange(); zedGraphControl.Invalidate(); }
private void CreateGraph(ZedGraphControl zg1) { // get a reference to the GraphPane myPane = zg1.GraphPane; // Set the Titles myPane.Title = "Максимальная температура"; myPane.XAxis.Title = "Название"; myPane.YAxis.Title = "Температура в градусах цельсия"; // Make up some random data points string[] labels = new string[bs.Count]; double[] temperature = new double[bs.Count]; for (int i = 0; i < bs.Count; i++) { labels[i] = objects[i].Name; temperature[i] = objects[i].Tmax; } // Generate a red bar with "Curve 1" in the legend BarItem myBar = myPane.AddBar("Температура", null, temperature, Color.Red); myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red); // Set the XAxis labels myPane.XAxis.TextLabels = labels; // Set the XAxis to Text type myPane.XAxis.Type = ZedGraph.AxisType.Text; // Tell ZedGraph to refigure the // axes since the data have changed zg1.AxisChange(); }
private void CreateGraph(ZedGraphControl zed, int[] values) { // get a reference to the GraphPane GraphPane myPane = zed.GraphPane; // Set the Titles myPane.Title.Text = "Histogram"; myPane.XAxis.Title.Text = "X Axis"; myPane.YAxis.Title.Text = "Y Axis"; myPane.XAxis.Scale.MajorStep = 5; // Make up some data arrays based on the Sine function double x; PointPairList list = new PointPairList(); for (int i = 0; i < values.Length; i++) { x = (double)i; list.Add(x, values[i]); } // Generate a red curve with diamond // symbols, and "Porsche" in the legend BarItem myBar = myPane.AddBar(null, list, Color.Black); myBar.Bar.Border.IsVisible = false; // Tell ZedGraph to refigure the // axes since the data have changed zed.AxisChange(); }
/// <summary> /// Creates the chart using the specified GraphItems. /// </summary> /// <param name="gItems">GraphItems to use</param> private void CreateChart(List <GraphItems> gItems) { try { List <double> y = new List <double>(); List <string> lbls = new List <string>(); for (int i = 0; i < gItems.Count; i++) { y.Add((double)gItems[i].Count); if (!String.IsNullOrEmpty(gItems[i].Name)) { lbls.Add(gItems[i].Name); } else { lbls.Add("Blank"); } } GraphPane myPane = zgGraph.GraphPane; myPane.XAxis.Scale.TextLabels = lbls.ToArray(); BarItem myCurve = myPane.AddBar(gTitle, null, y.ToArray(), Color.White); myCurve.Bar.Fill.Color = Color.CornflowerBlue; myCurve.Bar.Fill.Type = FillType.GradientByY; myCurve.Label.IsVisible = true; zgGraph.AxisChange(); RefreshGraph(); } catch (Exception ex) { Log.Instance.LogException(ex).Report(); } }
private void SetupGraphForAvgValue(double[] values, string valuename) { GraphPane myPane = zedGraphControl1.GraphPane; // Set the Titles myPane.Title.Text = "Average " + valuename; myPane.XAxis.Title.Text = "Day"; myPane.YAxis.Title.Text = "Frequency"; string[] labels = { "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun" }; double[] y1 = values; BarItem myBar = myPane.AddBar(valuename, null, y1, Color.Red); myBar.Bar.Fill = new Fill(Color.Red, Color.White, Color.Red); myPane.XAxis.MajorTic.IsBetweenLabels = true; // Set the XAxis labels myPane.XAxis.Scale.TextLabels = labels; // Set the XAxis to Text type myPane.XAxis.Type = AxisType.Text; }
private void UpdateGraphManaCurve() { zgManaCurve.GraphPane.CurveList.Clear(); GraphPane pane = zgManaCurve.GraphPane; pane.Title.Text = String.Format("Mana Curve - {0}", CardCountText()); PointPairList points = new PointPairList(); points.AddRange(cards.Where(wh => !wh.IsInSideboard) .Where(sel => !sel.Type.Contains("Land") && !sel.Type.Contains("Scheme")) .GroupBy(grp => grp.CalculatedManaCost) .OrderBy(ord => ord.Key) // Order x-Axis .Select(sel => new PointPair(sel.Key, sel.Sum(sum => sum.Amount)))); BarItem barChart = pane.AddBar("", points, Color.Blue); barChart.Bar.Fill.Type = FillType.Solid; pane.XAxis.Scale.Min = 0; pane.XAxis.Scale.MinorStep = 1; pane.XAxis.Scale.MajorStep = 1; pane.XAxis.Title.IsVisible = false; pane.YAxis.Scale.Min = 0; pane.YAxis.Scale.MinorStep = 1; pane.YAxis.Scale.MajorStep = 1; pane.YAxis.Title.IsVisible = false; zgManaCurve.AxisChange(); //zgManaCurve.Invalidate(); //zgManaCurve.Refresh(); }
private void ShowGraph(DataTable _dt, string graphtitle) { ZedGraphControl zgc = new ZedGraphControl(); zgc.IsEnableHZoom = false; zgc.IsEnableVZoom = false; GraphPane myPane = zgc.GraphPane; List <string> xname = new List <string>(); myPane.Title.Text = graphtitle; myPane.XAxis.Title.Text = ""; myPane.YAxis.Title.Text = ""; PointPairList list = new PointPairList(); for (int i = 0; i < _dt.Rows.Count; i++) { list.Add(0.0, Convert.ToDouble(_dt.Rows[i][_dt.Columns.Count - 1].ToString()), _dt.Rows[i][_dt.Columns.Count - 4].ToString()); // list.Add(0.0, Convert.ToDouble(_dt.Rows[i]["yValue"].ToString()), _dt.Rows[i]["xValue"].ToString()); // xname.Add(_dt.Rows[i]["xValue"].ToString()); xname.Add(_dt.Rows[i][_dt.Columns.Count - 4].ToString()); } BarItem myCurve = myPane.AddBar(null, list, Color.Blue); myPane.XAxis.Type = AxisType.Text; myPane.XAxis.Scale.TextLabels = xname.ToArray(); myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 45.0F); BarItem.CreateBarLabels(myPane, false, ""); zgc.AxisChange(); zgc.Refresh(); this.panelyr.Controls.Clear(); this.panelyr.Controls.Add(zgc); zgc.Dock = DockStyle.Fill; }
public void DrawLayers(IList <Tuple <Tuple <double, double>, double> > points, string title, string yAxisTitle, string xAxisTitle) { gp.Title.Text = title; gp.YAxis.Title.Text = yAxisTitle; gp.XAxis.Title.Text = xAxisTitle; gp.CurveList.Clear(); PointPairList list = new PointPairList(); string[] names = new string[points.Count]; int i = 0; foreach (Tuple <Tuple <double, double>, double> point in points) { list.Add(point.Item1.Item1, point.Item2); names[i] = String.Format("от {0} до {1} ", Math.Round(point.Item1.Item1 * 1E+5, 3), Math.Round(point.Item1.Item2 * 1E+5, 3)); i++; } BarItem curve = gp.AddBar("", list, Color.Blue); gp.BarSettings.MinClusterGap = 5; gp.XAxis.Type = AxisType.Text; gp.XAxis.Scale.TextLabels = names; gp.XAxis.Scale.FontSpec.Size = 10; Graph.AxisChange(); Graph.Invalidate(); }
private void UpdateGraph(ZedGraphControl graphControl, CenterSpace.Free.Histo histo) { //Build the graph GraphPane pane1 = graphControl.GraphPane; //Restart pane1.CurveList.Clear(); pane1.Title.Text = comboBoxTestToProcess.Text.Replace(".csv", ""); pane1.XAxis.Title.Text = "Bins"; pane1.YAxis.Title.Text = "Count"; //pane1.YAxis.Scale.Max = 3500; //pane1.XAxis.Scale.Min = -450; //pane1.XAxis.Scale.Max = 450; PointPairList histoList = new PointPairList(); for (int i = 0; i < histo.Counts.Length; i++) { histoList.Add(histo.BinBoundaries[i], histo.Counts[i]); } BarItem histoBar = pane1.AddBar("Count", histoList, Color.Aqua); graphControl.AxisChange(); graphControl.Invalidate(); }
private void InitGraph( string title, string xAxisTitle, string y1AxisTitle, string y2AxisTitle, SummaryDataSource[] dataSourceArray) { _graphPane = zed.GraphPane; _graphPane.Title.Text = title; _graphPane.XAxis.Title.Text = xAxisTitle; _graphPane.XAxis.MajorGrid.IsVisible = true; _graphPane.YAxis.Title.Text = y1AxisTitle; _graphPane.YAxis.MajorGrid.IsVisible = true; _graphPane.Y2Axis.Title.Text = y2AxisTitle; _graphPane.Y2Axis.MajorGrid.IsVisible = false; // Create point-pair lists and bind them to the graph control. int sourceCount = dataSourceArray.Length; _pointPlotArray = new PointPairList[sourceCount]; for (int i = 0; i < sourceCount; i++) { SummaryDataSource ds = dataSourceArray[i]; _pointPlotArray[i] = new PointPairList(); Color color = _plotColorArr[i % 3]; BarItem barItem = _graphPane.AddBar(ds.Name, _pointPlotArray[i], color); barItem.Bar.Fill = new Fill(color); _graphPane.BarSettings.MinClusterGap = 0; barItem.IsY2Axis = (ds.YAxis == 1); } }
private void BindDataForChart(GraphPane myPane) { int rowCount = gvEmployeeStatisticsSource.Rows.Count - 1;//排除总计 int colCount = gvEmployeeStatisticsSource.Columns.Count - 2; //绑定数据 string[] xDepartments = new string[rowCount]; for (int i = 0; i < rowCount; i++) { xDepartments[i] = gvEmployeeStatisticsSource.Rows[i][0].ToString(); } double[][] datas = new double[colCount][]; for (int i = 0; i < colCount; i++) { datas[i] = new double[rowCount]; for (int j = 0; j < rowCount; j++) { datas[i][j] = Convert.ToDouble(gvEmployeeStatisticsSource.Rows[j][i + 1]);//排除部门人数列 } myPane.AddBar(gvEmployeeStatisticsSource.Columns[i + 1].ColumnName, null, datas[i], Color.DimGray); } myPane.XAxis.MajorTic.IsBetweenLabels = true; myPane.XAxis.Scale.TextLabels = xDepartments; myPane.XAxis.Type = AxisType.Text; myPane.BarSettings.Type = BarType.Cluster; myPane.BarSettings.Base = BarBase.X; }
/// <summary> /// create a frequency plot of the selected variable; uses 9 categories /// </summary> /// <param name="iv">double array of independent variable values</param> /// <param name="tags"></param> /// <returns>graph pane to display in the master pane</returns> private GraphPane addPlotFQ(double[] iv) { //ncats is the number of categories const int ncats = 9; VBStatistics.Frequency counts = new VBStatistics.Frequency(); counts.getHist(iv, ncats); double[] c = counts.Counts; double[] center = counts.Center; GraphPane gp = new GraphPane(); PointPairList ppl = new PointPairList(); ppl.Add(center, c); BarItem bar = gp.AddBar(_dt.Columns[intSelectedcol].ColumnName, ppl, Color.Black); gp.XAxis.Title.Text = _dt.Columns[intSelectedcol].ColumnName; gp.YAxis.Title.Text = "Count"; gp.Title.Text = "Frequency Plot"; gp.Tag = "FREQPlot"; return(gp); }
public void ShowHistogram(string legend, double[] x, double[] y) { BarItem bar = GraphPane.AddBar(legend, x, y, NextColor()); AxisChange(); Invalidate(); }
public void DrawGraph(ICollection <double> array) { GraphPane pane = zedGraph.GraphPane; pane.CurveList.Clear(); var itemscount = array.Count; var barPosition = new double[itemscount]; for (int i = 0; i < itemscount; i++) { barPosition[i] = i + 1; } pane.AddBar("", barPosition, array.ToArray(), Color.Blue); pane.XAxis.Scale.Min = 0; pane.XAxis.Scale.Max = itemscount + 1; pane.YAxis.Scale.Max = 1; pane.XAxis.Scale.MajorStepAuto = true; pane.XAxis.Scale.MinorStep = 1; zedGraph.AxisChange(); zedGraph.Invalidate(); }
/// <summary> /// Creates a new CurveItem using the PointPairList and add it the the given pane. /// </summary> /// <param name="pane">the GraphPane object to which to add the new curve</param> /// <param name="points">a PointPairList collection defining the points for this curve</param> /// <returns>the newly created CurveItem added to the given GraphPane</returns> /// <remarks>This method must be overriden by childs</remarks> public override CurveItem CreateInPane( GraphPane pane, PointPairList points ) { BarItem x = pane.AddBar( this.Label, points, this.Color ); this.CopyTo( x ); return x; }
/// <summary> /// Renders the demo graph with one call. /// </summary> /// <param name="g">A <see cref="Graphics"/> object for which the drawing will be done.</param> /// <param name="pane">A reference to the <see cref="GraphPane"/></param> public static void RenderDemo(IGraphics g, GraphPane pane) { // Set the titles and axis labels pane.Title.Text = "Wacky Widget Company\nProduction Report"; pane.XAxis.Title.Text = "Time, Days\n(Since Plant Construction Startup)"; pane.YAxis.Title.Text = "Widget Production\n(units/hour)"; LineItem curve; // Set up curve "Larry" double[] x = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}; double[] y = {20, 10, 50, 25, 35, 75, 90, 40, 33, 50}; // Use green, with circle symbols curve = pane.AddCurve("Larry", x, y, Color.Green, SymbolType.Circle); curve.Line.Width = 1.5F; // Fill the area under the curve with a white-green gradient curve.Line.Fill = new Fill(Color.White, Color.FromArgb(60, 190, 50), 90F); // Make it a smooth line curve.Line.IsSmooth = true; curve.Line.SmoothTension = 0.6F; // Fill the symbols with white curve.Symbol.Fill = new Fill(Color.White); curve.Symbol.Size = 10; // Second curve is "moe" double[] x3 = {150, 250, 400, 520, 780, 940}; double[] y3 = {5.2, 49.0, 33.8, 88.57, 99.9, 36.8}; // Use a red color with triangle symbols curve = pane.AddCurve("Moe", x3, y3, Color.FromArgb(200, 55, 135), SymbolType.Triangle); curve.Line.Width = 1.5F; // Fill the area under the curve with semi-transparent pink using the alpha value curve.Line.Fill = new Fill(Color.White, Color.FromArgb(160, 230, 145, 205), 90F); // Fill the symbols with white curve.Symbol.Fill = new Fill(Color.White); curve.Symbol.Size = 10; // Third Curve is a bar, called "Wheezy" double[] x4 = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}; double[] y4 = {30, 45, 53, 60, 75, 83, 84, 79, 71, 57}; BarItem bar = pane.AddBar("Wheezy", x4, y4, Color.SteelBlue); // Fill the bars with a RosyBrown-White-RosyBrown gradient bar.Bar.Fill = new Fill(Color.RosyBrown, Color.White, Color.RosyBrown); // Fourth curve is a bar double[] x2 = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}; double[] y2 = {10, 15, 17, 20, 25, 27, 29, 26, 24, 18}; bar = pane.AddBar("Curly", x2, y2, Color.RoyalBlue); // Fill the bars with a RoyalBlue-White-RoyalBlue gradient bar.Bar.Fill = new Fill(Color.RoyalBlue, Color.White, Color.RoyalBlue); // Fill the pane background with a gradient pane.Fill = new Fill(Color.WhiteSmoke, Color.Lavender, 0F); // Fill the axis background with a gradient pane.Chart.Fill = new Fill(Color.FromArgb(255, 255, 245), Color.FromArgb(255, 255, 190), 90F); // Make each cluster 100 user scale units wide. This is needed because the X Axis // type is Linear rather than Text or Ordinal pane.BarSettings.ClusterScaleWidth = 100; // Bars are stacked pane.BarSettings.Type = BarType.Stack; // Enable the X and Y axis grids pane.XAxis.MajorGrid.IsVisible = true; pane.YAxis.MajorGrid.IsVisible = true; // Manually set the scale maximums according to user preference pane.XAxis.Scale.Max = 1200; pane.YAxis.Scale.Max = 120; // Add a text item to decorate the graph var text = new TextObj("First Prod\n21-Oct-93", 175F, 80.0F); // Align the text such that the Bottom-Center is at (175, 80) in user scale coordinates text.Location.AlignH = AlignH.Center; text.Location.AlignV = AlignV.Bottom; text.FontSpec.Fill = new Fill(Color.White, Color.PowderBlue, 45F); text.FontSpec.StringAlignment = StringAlignment.Near; pane.GraphObjList.Add(text); // Add an arrow pointer for the above text item var arrow = new ArrowObj(Color.Black, 12F, 175F, 77F, 100F, 45F); arrow.Location.CoordinateFrame = CoordType.AxisXYScale; pane.GraphObjList.Add(arrow); // Add a another text item to to point out a graph feature text = new TextObj("Upgrade", 700F, 50.0F); // rotate the text 90 degrees text.FontSpec.Angle = 90; // Align the text such that the Right-Center is at (700, 50) in user scale coordinates text.Location.AlignH = AlignH.Right; text.Location.AlignV = AlignV.Center; // Disable the border and background fill options for the text text.FontSpec.Fill.IsVisible = false; text.FontSpec.Border.IsVisible = false; pane.GraphObjList.Add(text); // Add an arrow pointer for the above text item arrow = new ArrowObj(Color.Black, 15, 700, 53, 700, 80); arrow.Location.CoordinateFrame = CoordType.AxisXYScale; arrow.Line.Width = 2.0F; pane.GraphObjList.Add(arrow); // Add a text "Confidential" stamp to the graph text = new TextObj("Confidential", 0.85F, -0.03F); // use ChartFraction coordinates so the text is placed relative to the ChartRect text.Location.CoordinateFrame = CoordType.ChartFraction; // rotate the text 15 degrees text.FontSpec.Angle = 15.0F; // Text will be red, bold, and 16 point text.FontSpec.FontColor = Color.Red; text.FontSpec.IsBold = true; text.FontSpec.Size = 16; // Disable the border and background fill options for the text text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; // Align the text such the the Left-Bottom corner is at the specified coordinates text.Location.AlignH = AlignH.Left; text.Location.AlignV = AlignV.Bottom; pane.GraphObjList.Add(text); // Add a BoxObj to show a colored band behind the graph data var box = new BoxObj(0, 110, 1200, 10, Color.Empty, Color.FromArgb(225, 245, 225)); box.Location.CoordinateFrame = CoordType.AxisXYScale; // Align the left-top of the box to (0, 110) box.Location.AlignH = AlignH.Left; box.Location.AlignV = AlignV.Top; // place the box behind the axis items, so the grid is drawn on top of it box.ZOrder = ZOrder.D_BehindAxis; pane.GraphObjList.Add(box); // Add some text inside the above box to indicate "Peak Range" var myText = new TextObj("Peak Range", 1170, 105); myText.Location.CoordinateFrame = CoordType.AxisXYScale; myText.Location.AlignH = AlignH.Right; myText.Location.AlignV = AlignV.Center; myText.FontSpec.IsItalic = true; myText.FontSpec.IsBold = false; myText.FontSpec.Fill.IsVisible = false; myText.FontSpec.Border.IsVisible = false; pane.GraphObjList.Add(myText); pane.AxisChange(g); }