B4J Question Solved: xChart: Mark the clicked Point on the chart

GabrielM

Member
Licensed User
Longtime User
Need some guidance on how to mark a Point on a SingleLine graph when the user clicks a Point on the graph, please?

In code I have the PointType set to "NONE", initially.

I am looking on how to use something like the parameters (Pointype, PointColor, Filled) found on the "Addline2", or even a vertical line, so that I could have the selected(clicked) Point marked there in graph, until I will select(click) another Point.

I have attached the existing code.
 

Attachments

  • ChartsDemo.zip
    28.4 KB · Views: 258

klaus

Expert
Licensed User
Longtime User
Can you be more precise on what exactly you want to do.
Currently a vertical line and the point values are displayed.
What is the purpose of displaying the selected point or line and maintain it?

You draw a single line with no points drawn.
Then, when the user clicks on the chart, what do you want to display?
The nearest point where ever the user clicks, or only when the user clicks near a point.
Do you want to display also the value of the point?

This feature needs to modify the Class code.
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Looking to have the Red color line remaining there after the mouse click.
Reason:
- is for the user to have a graphical representation of the selected Point that was clicked previously, so then the user could poke around selecting another value. That is almost the same action like in a Scope when you move the cursor and select say Start Point then the End Point.
- I see it as a range the user want to select by clicking on the graph and selecting Start and End Points.

Yes, the nearest Point when clicked.

Displaying the value would be a great bonus.
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Something like that: Start_End_Ex.jpg
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
After selecting the two point:
- will save a SnapShot of Graph
- perform specific calculations based on the X values of the respective Points.
- clear the two selected Points on the Graph via a Button
- load a new set of data.

Thank you for the link on xGraph Class, will check it right now.
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Seems that xChart is much closer to what I am after. I will go with that.
Many thanks, Klaus.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I understand your request!
But, sorry, for a bit being pedantic and annoying, before adding anything to an existing software or developing something new, I need to know in detail all the concerns.
In my opinion your request is too specific to add it as a 'standard' method in xChart.
I don't want to make this class too complicated with more and more specific methods, it is already a bit complicated.

With your comments:
After selecting the two points:
- will save a SnapShot of Graph?

Which snapshot? The one with the two selected lines, or the zoomed one?

- perform specific calculations based on the X values of the respective Points.
What kind of calculations ?

- clear the two selected Points on the Graph via a Button.
What for? Clear the two points after calculations? Or, what else?

- load a new set of data.
The zoomed data or anything else?

I wrote the xGraph class for graphical data analysis, including calculations, and display data.
To me it looks like that this is what your trying to do.
The xChart class is intended for display, not for analysis and I want to keep it like this.
So, I know what you are missing in xChart, but what do you miss in xGraph?
Both can be improved! But I must be convinced to do it :) !

Maybe, have a look at the DynSim project, it shows what I mean with graphical data analysis.
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
By no means was asking to have a modified class.
I really appreciate your guidance, and thank you very much for it, I have an idea of what to do next so I am very happy, no worries at all.
I should have this thread marked as Solved now.
Many thanks.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Well, I will add two cursors to the xGraph class.
These can be interesting for calculations.
For example:
- calculate the difference between two cursors in the X axis.
- if the X axis is a time, convert the time difference into a frequency.
The last is interesting if you have a sine signal and you set the two cursors on two summits you get the frequency.

In the DynSim project, in the Graphic module there are two cursors to calculate a frequency.
I hadn't added those yet in the xGraph class.

I had in mind to write a more complete xGraph class with quite some additional functions for calculations like the Graphic module in the DynSim project, but I am afraid that there is not much interest.

Some calculation methods on curves are already included in the xGraph class, like:
- Add an offset to a curve.
- Multiply a curve by a constant.
- Add two curves.
- Subtract two curves.
- Multiply two curves.
- Divide two curves.
- Derivation of a curve.
- Integration of a curve.
- Calculate the mean value.
All these calculations can be made on the entire curve or only on the zoomed part of the curve.
 
Upvote 0

GabrielM

Member
Licensed User
Longtime User
Definitely your xGraph class is already providing enough functionality calculations dealing with respective curves used.
The additional two cursors will add a great value to your class and hopefully it is not just myself looking forward to see that.

As per your advice I have tried to modify the xChart class for proof of concept to have two distinct and user select-able markers, and to be able to store or otherwise use these markers x/y values in whatever own functions I might need to do.

I have attached here a simplified running code of what I have tried so far, and it is just enough for me.
 

Attachments

  • ChartsDemo_two_markers.zip
    29.5 KB · Views: 246
Upvote 0
Top