7 Replies - 9481 Views - Last Post: 17 June 2009 - 07:26 AM Rate Topic: -----

#1 bjmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-June 09

Zedgraph help User Input data

Post icon  Posted 15 June 2009 - 07:57 AM

Hello, I'm just trying to create a graph where the user can input data into textboxes and then plot the data. I am attempting to use Zedgraph, but open to other suggestions. The program below creates a plot, but it won't update when the textboxes are updated. Can you help me please? Thanks,


Imports ZedGraph

Public Class Form1

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		CreateGraph(zg1)
		SetSize()
	End Sub

	Private Sub CreateGraph(ByVal zgc As ZedGraphControl)
		Dim myPane As GraphPane = zgc.GraphPane

		' Set the title and axis labels
		myPane.Title.Text = "PVT Properties"
		myPane.XAxis.Title.Text = "Pressure (atm)"
		myPane.YAxis.Title.Text = "Temperature (C)"

		' Enter some calculated data constants   
		Dim list1 As New PointPairList()
		Dim x1 As Single = 0
		Dim y1 As Single = 0

		If Not String.IsNullOrEmpty(TextBox1.Text) Then
			x1 = CDbl(TextBox1.Text)
		Else
			TextBox1.Text = 0
		End If

		If Not String.IsNullOrEmpty(TextBox2.Text) Then
			y1 = CDbl(TextBox2.Text)
		Else
			TextBox2.Text = 0
		End If


		list1.Add(x1, y1, 31.67)

		' Generate a red curve with diamond symbols, and "Gas Data" in the legend
		Dim myCurve As LineItem = myPane.AddCurve("Gas Data", list1, Color.Red, _
							 SymbolType.Diamond)
		myCurve.Symbol.Size = 12
		' Set up a red-blue color gradient to be used for the fill
		myCurve.Symbol.Fill = New Fill(Color.Red, Color.Blue)
		' Turn off the symbol borders
		myCurve.Symbol.Border.IsVisible = False
		' Instruct ZedGraph to fill the symbols by selecting a color out of the
		' red-blue gradient based on the Z value.  A value of 19 or less will be red,
		' a value of 34 or more will be blue, and values in between will be a
		' linearly apportioned color between red and blue.
		myCurve.Symbol.Fill.Type = FillType.GradientByZ
		myCurve.Symbol.Fill.RangeMin = 19
		myCurve.Symbol.Fill.RangeMax = 34
		' Turn off the line, so the curve will by symbols only
		myCurve.Line.IsVisible = False

		' Display a text item with "MW = 34" on the graph
		Dim text As New TextObj("MW = 34", 12.9F, 110, CoordType.AxisXYScale)
		text.FontSpec.FontColor = Color.Blue
		text.FontSpec.Border.IsVisible = False
		text.FontSpec.Fill.IsVisible = False
		text.FontSpec.Size = 14
		myPane.GraphObjList.Add(text)

		' Display a text item with "MW = 19" on the graph
		text = New TextObj("MW = 19", 25, 110, CoordType.AxisXYScale)
		text.FontSpec.FontColor = Color.Red
		text.FontSpec.Border.IsVisible = False
		text.FontSpec.Fill.IsVisible = False
		text.FontSpec.Size = 14
		myPane.GraphObjList.Add(text)


		' Show the X and Y grids
		myPane.XAxis.MajorGrid.IsVisible = True
		myPane.YAxis.MajorGrid.IsVisible = True

		' Set the x and y scale and title font sizes to 14
		myPane.XAxis.Scale.FontSpec.Size = 14
		myPane.XAxis.Title.FontSpec.Size = 14
		myPane.YAxis.Scale.FontSpec.Size = 14
		myPane.YAxis.Title.FontSpec.Size = 14
		' Set the GraphPane title font size to 16
		myPane.Title.FontSpec.Size = 16
		' Turn off the legend
		myPane.Legend.IsVisible = False

		' Fill the axis background with a color gradient
		myPane.Chart.Fill = New Fill(Color.White, Color.FromArgb(255, 255, 166), 90.0F)

		' Calculate the Axis Scale Ranges
		zgc.AxisChange()
	End Sub
	Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
		SetSize()
	End Sub
	Private Sub SetSize()
		zg1.Location = New Point(10, 10)
		' Leave a small margin around the outside of the control
		zg1.Size = New Size(ClientRectangle.Width - 20, ClientRectangle.Height - 20)
	End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Replies To: Zedgraph help User Input data

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Zedgraph help User Input data

Posted 15 June 2009 - 08:13 AM

Not sure how your program works at all. variables should be contiguous e.g. "y1" not "y 1". A space means some new token follows for the compiler.

For the update, you need to act on one of two events. You can either catch the event that the contents of a TextBox has changed (not recommended as it fiires for each character edited) or provide a recalc button that calls create graph when the user is ready.
Was This Post Helpful? 0
  • +
  • -

#3 bjmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-June 09

Re: Zedgraph help User Input data

Posted 16 June 2009 - 05:09 AM

Thanks a million for taking the time to respond to this Mark. I've tried posting all over the place and never get a reply. I actually don't have spaces in my names. It's just a font issue since my computer runs on Chinese Windows, it sometimes does that.

I thought that I would have to add a button to perform the recalc, but I've been unsuccessful. Do you have an example of how to implement this. Sorry, I am very new to programming and I'm in a remote area so I can't find English books on such topics. I have been working very hard on trying to get this to work though.

best regards,
Bob
Was This Post Helpful? 0
  • +
  • -

#4 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Zedgraph help User Input data

Posted 16 June 2009 - 07:07 AM

First, several style fixes:
1) PLEASE use meaningful names for controls - e.g. TextBox1 should be something like txtXDatum, or whatever. This makes it more easily comprehensible by others reading your code. Code is written, not for compilers but for other coders and yourself to read in the future.
2) Never call an Object instance using a word that can be confused with existing attributes e.g. Dim <b>text</b> As New TextObj("MW = 34", 12.9F, 110, CoordType.AxisXYScale) is a terrible name, maybe axisLabel??

It looks like you try to graph based on the start values of the input data textboxes and they usually contain 0 or Nothing or and empty string on startup. Event driven programming is all about doing work when something changes. Either a user click, a timer tick, data arrival, etc.

You need to separate CreateGraph into at least 2 parts. The first part configures the graph label, colours, background etc., but does not plot any data. The second will be the recalc button that will read the new x/y data point and then update the plot using new data and then changing the scaling as necessary.

A likely follow-on will be a reset button that will remove all the data points from the list and reset the graph plot.

Add a Button labeled Recalc in your Designer (it looks like you will need to adjust the zg1 size to allow space on the form). Double click on the button and it will take you to an empty sub routine that handles the Button's Click event. In the subroutine, do the plot update work. That should be all that is necessary as far as I can tell from your code.
Was This Post Helpful? 0
  • +
  • -

#5 Cookiesliyr  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 136
  • Joined: 16-May 09

Re: Zedgraph help User Input data

Posted 16 June 2009 - 07:33 AM

i read ur problem and unfortunately cause i don't have ZedGraph class i don't know how its work and what's functions look like and do, but i think when i show u the way u will know how it will work

simply when u double click on a textbox on ur form it will open ur code page and the IDE will insert u the sub for the textbox with the event TextChange like this

private sub Text_TextChanged (byblah blah blah) handles Text.TextChanged 

end sub



whenever the text box data change the sub will be called , i think if u but SetSize() inside it it will work , aren't u calling it to update the graph ?

hope it will works fine with u
Was This Post Helpful? 0
  • +
  • -

#6 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Zedgraph help User Input data

Posted 16 June 2009 - 10:09 AM

Don't use TextChanged as it fires an event on EVERY character typed into the box or deleted from the box. Stick to the separate button.
Was This Post Helpful? 0
  • +
  • -

#7 bjmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-June 09

Re: Zedgraph help User Input data

Posted 17 June 2009 - 06:38 AM

Thanks again for the replies. I have been heading down the path suggested of adding a button as a second part of the program, but I'm not quite sure how to structure it. I tried just creating a sub for the button click event but it didn't work at all. Maybe I just wrote it incorrectly.

Instead of doing a textbox TextChanged event, I tried to use the Textbox Enter event to update the textboxes but that didn't do anything either. Again, perhaps just written incorrectly.

Mark, when you say the program should be two parts, does that mean something like two classes? Zedgraph seems like a great program, there's just not much help on the website. I'd be open to other graphing suggestions as well.

Take care,
Bob
Was This Post Helpful? 0
  • +
  • -

#8 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Zedgraph help User Input data

Posted 17 June 2009 - 07:26 AM

I mean that the Create_Graph subroutine should be 2 separate subroutines. One subroutine called at the start of the world will configure those parts of the graphing that are static like the labels, the graph size, etc. the second subroutine called from the recalcualte button click will add the new data point and cause the graph to update it's scaling and it's output graph line. You are currently mixing the preparing of the graph module with the work of drawing and re-drawing the actual line with the data.

We are also not yet psychic, so posting the code from your attempts may be more helpful to you, (yes even from failed attempts.)

This post has been edited by mark.bottomley: 17 June 2009 - 07:27 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1