B4J Question x, y plot

bdunkleysmith

Active Member
Licensed User
Longtime User
As part of a B4J application I finish up with a table of data consisting of x and y coordinates (both in the range 0 - 100) and for each point value of 1 or 0.

I want to produce a (scatter?) plot of those points, with the shape of the plotted point being determined by whether its value is 1 or 0. For instance 1 could be shown as x and 0 as o, but any distinguishable shape would be OK such as a square and circle.

I'm just looking for a pointer on what method would suit and where to start. I was thinking javafx.scene.shape may be is where I should be.

Thanks in anticipation of any suggestions.

Bryon
 

Daestrum

Expert
Licensed User
Longtime User
You could use the scatterchart object to display your data. Its quite easy to add to your project.
Have attached example for you to try.
 

Attachments

  • scatterchart example.zip
    1.2 KB · Views: 245
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Daestrum,

Thanks again for your great help. I've been able to produce the basic chart:

ScatterChart.png

but can I ask a few questions?
  • I can't see how the color and shape of the points in each series is set - where is that done?
  • If the line MainForm.RootPane.AddNode(inline.RunMethod("getChart",Null),10,10,310,310) places the scatter chart in the MainForm, how do I remove the chart so it is not visible, but MainForm remains?
  • How can I clear the displayed data with the chart framework remaining so i can display new data, presumably by invoking the line inline.RunMethod("addData",Array(x,y,v))?
  • Would it be possible to set the background of the chart to an image so the scatter points are overlaid on the image?
Thanks,

Bryon
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I can answer some of your questions
1, It is set from css (haven't managed to get this working as I am rubbish at css)
2, You can change the code slightly to allow for this
B4X:
    .....
    Dim sc As Node
    sc = inline.RunMethod("getChart",Null)
    MainForm.RootPane.AddNode(sc,10,10,410,410)
You can then remove the node from mainform as normal
3, You can use remove function to get rid of a series
4, Yes you can have an image as a background, again css is used

This page may be useful https://docs.oracle.com/javafx/2/charts/css-styles.htm
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
I thought css may be involved and you've confirmed that for me.

I've been able to produce a css file (and load it) that sets the shape and color of the points and sets the background of the chart to an image. Dimensioning sc as a node has also allowed me to be able to remove it. So now I've just the implementation of the remove function to get rid of the series.

Thanks again for your help.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You can use similar to this
B4X:
    inline.RunMethod("removeSeries1",Null)
B4X:
public static void removeSeries1(){
    sc.getData().remove(series1);
}
 
Upvote 0
Top