Graph Control(ZedGraph Control)

hi to all,
The following is the code useful drawing graph with different curves with different colors by reading from text file.

private void StripButton_Start_Click(object sender, EventArgs e)
// zgc means Zedgraph name,mypane means graph body
myPane = zgc.GraphPane;
// Draw Curve
myCurve = myPane.AddCurve("", list, Color.Red, SymbolType.Circle);
myCurve.Symbol.Size = 5.0F;
myCurve.Symbol.Fill = new Fill(Color.Black);
// Make up some data arrays based on the Sine function
objstream = new StreamReader("E:\\temp.txt"); //Reading data from text file//

// Generate a red curve with diamond
// symbols, and "Porsche" in the legend
zgc.ContextMenuBuilder += new ZedGraphControl.ContextMenuBuilderEventHandler(MyContextMenuBuilder);
// Set the Y axis intersect the X axis at an X value of 0.0
myPane.YAxis.Cross = 0.0;
// Calculate the Axis Scale Ranges

//Timer Enabled
timer1.Enabled = true;

private void timer1_Tick(object sender, EventArgs e)
GraphPane myPane = zgc.GraphPane;

// Reading the Upto End of File
while (!objstream.EndOfStream)
str = objstream.ReadLine();
textBox.Text = str;
string st = textBox6.Text;
object[] myColor ={ Color.Red, Color.Blue, Color.Yellow, Color.Green, Color.HotPink };
myCurve = myPane.AddCurve("", list, (Color)myColor[i], SymbolType.Circle);
if (str == "")
//Here I new graph Starts I want to change colors when new PointpairList start. How can i?

list = new PointPairList();
myCurve = myPane.AddCurve("",list, Color.Blue, SymbolType.Circle);
myCurve.Symbol.Size = 5.0F;
myCurve.Symbol.Fill = new Fill(Color.Red);
str = objstream.ReadLine() + "\n";


string str1 = str.Substring(0, st.IndexOf("\t"));
string str2 = str.Substring(st.IndexOf("\t"));
x = (float)Convert.ToDecimal(str1);
y = (float)Convert.ToDecimal(str2);
list.Add(x, y);



try this....


Author: Mrs. Meetu Choudhary Nanda21 Apr 2009 Member Level: Gold   Points : 2

Please Post Your Resources fully formatted it saves lots of time while editing use & lt instead of "<" and & gt instead of ">" so that your code will appear as you want other wise it will be interpreted as HTML Tags as they are allowed in the resources... and use code /code in the big brackets as special tag to display the code snippets...

Thanks and Regards
Meetu Choudhary

Author: CoolShru19 May 2010 Member Level: Bronze   Points : 0

I also have the sma problem. How to change the colors picked from an array

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: