본문 바로가기
c#

zedgraph

by [김경민]™ ┌(  ̄∇ ̄)┘™ 2013. 4. 27.
728x90

Vertical Bar With Labels Demo

From ZedGraphWiki

Jump to: navigation, search

NOTE: The code on this page is for ZedGraph version 5. You can view the code for version 4 here.


 

// Call this method from the Form_Load method, passing your ZedGraphControl
public void CreateChart( ZedGraphControl zgc )
{
   GraphPane myPane = zgc.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 );
 
   zgc.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" );

}

Go back to Sample Graphs

 

728x90

댓글