ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
|
Downloads |
Flexsim Student Forum Forum for discussion for Flexsim Students using the Flexsim Textbook. |
#1
|
|||
|
|||
Trouble making a custom line graph
I am trying to build a custom line graph in a custom GUI.
What I thought of doing was to use the drawline command to draw the line graph in increments. the problem is everytime it draws the next increment of the line the previous one disappears and instead of a line I see a worm moving!! . here is the code that I used in the ondraw attribute of the graph: treenode view = c; treenode waiting_area = node(">viewfocus+",view); double yvalue = getlabelnum(waiting_area,"Avg_WTBS"); double xvalue = getlabelnum(waiting_area,"PatientNumber")*.1; int lastx = getlabelnum(centerobject(waiting_area,1),"lastx"); int lasty = getlabelnum(centerobject(waiting_area,1),"lasty"); drawline(view,lastx,lasty,0,xvalue+1,yvalue,0,1,0, 1); setlabelnum(centerobject(waiting_area,1),"lastx",x value + 1); setlabelnum(centerobject(waiting_area,1),"lasty",y value); Last edited by mearjun; 12-19-2013 at 12:50 AM. |
#2
|
|||
|
|||
Hello mearjun,
You are drawing one (moving) point every time. Every time the OnDraw code is refreshed it starts with a blank sheet. If you want to draw 10 line segments, you will have to call the drawline command 10 times (you can use a for loop). For every segment you have to determine the start and end point. It could look something like: treenode view = c; treenode waiting_area = node(">viewfocus+",view); double yvalue = getlabelnum(waiting_area,"Avg_WTBS"); double xvalue = getlabelnum(waiting_area,"PatientNumber")*.1; int lastx = getlabelnum(centerobject(waiting_area,1),"lastx"); int lasty = getlabelnum(centerobject(waiting_area,1),"lasty"); int nrOfLines = 10; for( int x = 1; x <= nrOfLines; x++ ) { drawline(view,lastx,lasty,0,xvalue+1,yvalue,0,1,0, 1); lastx++; // adds 1 to the lastx value } Esther |
The Following User Says Thank You to Esther Bennett For This Useful Post: | ||
Jörg Vogel (12-19-2013) |
#3
|
|||
|
|||
Thanks for answering but I am not clear yet..Here is what I am trying to do. I want that whenever the value of a particular label changes a new point in the graph should be found such that new y is the label value and x increments by 1. When you say that I should use a for loop, how would I have all the possible values of y (label values) at one time ?
Maybe what I need to do is that the line I draw should be a permanent line and the ondraw trigger should not refresh the entire canvas the next time so that a curve is generated with the help of 1000s of small lines. |
#4
|
||||
|
||||
Hello,
you have to store all the values you want to print in the graph. You can use different methods to store values (table, tracked variables, bundles). Jörg |
The Following 3 Users Say Thank You to Jörg Vogel For This Useful Post: | ||
Steven Hamoen (12-20-2013) |
Thread | Thread Starter | Forum | Replies | Last Post |
Add Graph to custom GUI | mearjun | Flexsim Student Forum | 0 | 12-17-2013 04:41 AM |
Custom GUI: Graph OnDraw | Phil BoBo | Tips and Tricks | 2 | 05-16-2013 03:48 AM |
trouble overriding begintask() for a custom module | Vadim Fooks | Q&A | 2 | 04-08-2013 12:23 AM |
Show global variable as line graph in Recorder | Congshi Wang | Q&A | 1 | 12-08-2010 01:22 AM |
Need Example Graph in a UI ( With the Graph Control) | Gleny Rodriguez | Q&A | 2 | 06-09-2010 08:31 AM |