Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BLT stripchart - associate tag with individual data points 1

Status
Not open for further replies.

ajaayman

Programmer
Feb 14, 2003
12
0
0
US
I am trying to do the following:
I am using stripchart to create a scrolling graph (X axis time, Y axis data value). I would like to associate a tag with each data point,i.e. each data point need to have a unique tag(generated outside of the program). When a user clicks on a data point, I would read the tag and associate other data with this point.
Does anyone have any idea on how to do this? I have problem associating a unique tag with a data point.
Thanks.
 
I responded to Raj via private email, but I thought that others might be interested in the reply as well.

First, instead of creating a separate tag for each data point, you can bind directly to the element of interest. And second, look into the graph/stripchart's [element closest] operation, which determines the closest point of an element given an X,Y coordinate pair, and populates a given global array variable with the following array elements:

name Name of the closest element
dist Distance from the element
index Index of the element's closest data point
x and y The X-Y *graph* coordinates of the element's closest point

Here's a quick example of how you could combine these to get what you're after:

Code:
##################

package require BLT
namespace import blt::*

vector create x(20)
vector create y(20)

x seq 1 20
y random

graph .g
pack .g -expand yes -fill both

.g element create data -xdata x -ydata y

toplevel .report -bg black
label .report.info -textvariable status     -justify left -bg yellow
pack .report.info -padx 2 -pady 2

wm withdraw .report
wm overrideredirect .report 1

.g element bind data <ButtonPress-1> {
    if {[.g element closest %x %y click]} {
        set status &quot;Clicked on \&quot;$click(name)\&quot; element\n&quot;
        append status &quot;Data point $click(index)\n&quot;
        append status &quot;x value: $click(x), y value $click(y)&quot;
        
        wm geometry .report +%X+%Y
        wm deiconify .report
    }
}

.g element bind data <ButtonRelease-1> {
    wm withdraw .report
}

##################
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top