B4J Question What does this constructor expect to be passed to it?

Johan Schoeman

Expert
Licensed User
Longtime User
B4X:
    public XYPane(final XYSeries<T>... SERIES) {
        this(Color.TRANSPARENT, 1,  SERIES);
    }

My B4J code looks like this:

B4X:
    Dim lineChartPane As JavaObject
    lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(xySeries1, xySeries2))

The sample Java code creates a new instance as follows:
B4X:
       XYPane lineChartPane = new XYPane(xySeries1, xySeries2);

So, I am passing and array of XYSeries but I get an error that states:
B4X:
java.lang.RuntimeException: Constructor not found.

When I log "xySeries1" I get:
B4X:
(XYSeries) eu.hansolo.fx.charts.series.XYSeries@13fb3ece

No compiling error in the B4J code until I hit:
B4X:
 lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(xySeries1, xySeries2))

What needs to be passed to the constructor? A bit lost here...
 

Daestrum

Expert
Licensed User
Longtime User
I would guess try
B4X:
lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(xySeries1, Array(xySeries2)))
or
B4X:
lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(Array(xySeries1, xySeries2)))
(my gut feeling would be the second one)
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
I would guess try
B4X:
lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(xySeries1, Array(xySeries2)))
Same error.....

Just trying to pass a single series to the constructor also fails with the same error (java.lang.RuntimeException: Constructor not found.):
B4X:
    lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(xySeries1))
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
try the second version of my reply
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
VarArgs are quite tricky using JavaObject, you need to pass an array of the correct type (Object will not do).

You can use JavaObject InitializeArray to create the specific array type.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It/they will still need to be wrapped in an Object array as per JavaObject parameter passing.
 
Last edited:
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
try the second version of my reply
Unfortunately giving the same error...
B4X:
lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(Array(xySeries1, xySeries2)))
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
It will still need to be wrapped in an Object array as per JavaObject parameter passing.
Steve, I am trying this:
B4X:
    Dim javaobjectarray As JavaObject
    javaobjectarray.InitializeArray("eu.hansolo.fx.charts.XYPane", Array(xySeries1))
    Dim lineChartPane As JavaObject
    lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(javaobjectarray))

....and now get the following error:
B4X:
java.lang.IllegalArgumentException: array element type mismatch
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The array type should be whatever the data you are passing is, so it should be of type XYSeries, whatever the full classname for that is.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
The array type should be whatever the data you are passing is, so it should be of type XYSeries, whatever the full classname for that is.
This compiles fine:
B4X:
    Dim javaobjectarray As JavaObject
    javaobjectarray.InitializeArray("eu.hansolo.fx.charts.series.XYSeries", Array(xySeries1))
    Dim lineChartPane As JavaObject
    lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(javaobjectarray))

Will now try last step to get the chart to display.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
XYSeries<T>... SERIES
these ...-Variants are tricky.
Are there any other implementations available for this command. Any overloaded version wanting an Array or a List or a Collection instead of ...?
Can you give any link to the documentation?
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
these ...-Variants are tricky.
Are there any other implementations available for this command. Any overloaded version wanting an Array or a List or a Collection instead of ...?
Can you give any link to the documentation?
This is the link:
https://github.com/HanSolo/charts/tree/11.2

Under folder SRC there are folders Main and Test

Main = the library
Test = the sample projects

The Jar is in this post:
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Some finding
firefox_vKhTDKh5cK.png


internally the ... SERIES are transformed to an observerableArrayList based on SERIES.

There are overloaded Versions which do accept a List.
See https://docs.oracle.com/javase/8/javafx/api/javafx/collections/FXCollections.html

You can pass a B4J List to the wrapper.
The wrapper creates a java Arraylist based on the given B4J List

create a new constructor in the original library requiring a list
pass your generated arraylist when using the new constuctor.

Just an idea
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
The array type should be whatever the data you are passing is, so it should be of type XYSeries, whatever the full classname for that is.
I found the little sh1t:

1668347097593.png


Hansolo LineChart:
#Region Project Attributes
    #MainFormWidth: 1200
    #MainFormHeight: 800
#End Region

#AdditionalJar: charts-11.2
'#AdditionalJar: javafx-graphics-11
'#AdditionalJar: javafx-base-11


Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form

    Private Pane1 As Pane
    
    Dim chart As JavaObject


End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show



    
    Dim xySeriesBuilder As JavaObject
    xySeriesBuilder.InitializeStatic("eu.hansolo.fx.charts.series.XYSeriesBuilder")
    Dim xySeries1 As JavaObject
    xySeries1.InitializeNewInstance("eu.hansolo.fx.charts.series.XYSeries", Null)
    
    
    Dim xyChartItemList As List
    xyChartItemList.Initialize
    
    Dim number As Double = 1
    Dim value As Double = 600
    Dim description As String = "Jan"
    Dim xyChartItem As JavaObject
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 2
    value = 760
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 3
    value = 585
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 4
    value = 410
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 5
    value = 605
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 6
    value = 825
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 7
    value = 595
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 8
    value = 300
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 9
    value = 515
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 10
    value = 780
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 11
    value = 570
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    number = 12
    value = 620
    description = "Feb"
    xyChartItemList.add(xyChartItem.InitializeNewInstance("eu.hansolo.fx.charts.data.XYChartItem", Array(number, value, description)))
    
    
    Dim chartType As JavaObject
    chartType.InitializeStatic("eu.hansolo.fx.charts.ChartType")
    
    Dim fillColor As JavaObject
    fillColor.InitializeStatic("javafx.scene.paint.Color")
    Dim stringFillColor As String = "#00AEF520"
    
    Dim strokeColor As JavaObject
    strokeColor.InitializeStatic("javafx.scene.paint.Color")
    Dim stringStrokeColor As String = "#00AEF5"
    
    Dim symbolStrokeColor As JavaObject
    symbolStrokeColor.InitializeStatic("javafx.scene.paint.Color")
    Dim stringSymbolStrokeColor As String = "#293C47"
    

    Dim symbolSize As Double = 10
    Dim strokeWidth As Double = 3
    
    xySeries1 = xySeriesBuilder.RunMethodJO("create", Null) _
                               .RunMethodJO("items", Array(xyChartItemList)) _
                               .RunMethodJO("chartType", Array(chartType.GetField("SMOOTH_LINE"))) _
                               .RunMethodJO("fill", Array(fillColor.RunMethod("web", Array(stringFillColor)))) _
                               .RunMethodJO("stroke", Array(strokeColor.RunMethod("web", Array(stringStrokeColor)))) _
                               .RunMethodJO("symbolFill", Array(strokeColor.RunMethod("web", Array(stringStrokeColor)))) _
                               .RunMethodJO("symbolStroke", Array(symbolStrokeColor.RunMethod("web", Array(stringSymbolStrokeColor)))) _                               
                               .RunMethodJO("symbolSize", Array(symbolSize)) _
                               .RunMethodJO("strokeWidth", Array(strokeWidth)) _
                               .RunMethodJO("symbolsVisible", Array(True)) _
                               .RunMethodJO("build", Null)
    

    Dim xAxisBottom As JavaObject
    Dim bottomAxisBuilder As JavaObject
    xAxisBottom.InitializeNewInstance("eu.hansolo.fx.charts.Axis", Null)
    bottomAxisBuilder.InitializeStatic("eu.hansolo.fx.charts.AxisBuilder")

    Dim orientation As JavaObject
    orientation.InitializeStatic("javafx.geometry.Orientation")
    
    Dim position As JavaObject
    position.InitializeStatic("eu.hansolo.fx.charts.Position")
    
    Dim axisType As JavaObject
    axisType.InitializeStatic("eu.hansolo.fx.charts.AxisType")
    
    Dim categories As List
    categories.Initialize
    categories.AddAll(Array As String("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
    Dim minvalue As Double = 1
    Dim maxvalue As Double = 13
    

    Dim axisColor As JavaObject
    axisColor.InitializeStatic("javafx.scene.paint.Color")
    Dim stringAxisColor As String = "#85949B"
    
    Dim tickLabelColor As JavaObject
    tickLabelColor.InitializeStatic("javafx.scene.paint.Color")
    Dim stringTickLabelColor As String = "#85949B"
    
    Dim tickMarkColor As JavaObject
    tickMarkColor.InitializeStatic("javafx.scene.paint.Color")
    Dim stringTickMarkColor As String = "#85949B"

    Dim prefHeight As Double = 25
    Dim prefWidth As Double = 25
    Dim axisWidth As Double = 25
    xAxisBottom = bottomAxisBuilder.RunMethodJO("create", Array(orientation.GetField("HORIZONTAL"), position.GetField("BOTTOM"))) _
                             .RunMethodJO("type", Array(axisType.GetField("TEXT"))) _
                             .RunMethodJO("prefHeight", Array(prefHeight)) _
                             .RunMethodJO("categories", Array(categories)) _
                             .RunMethodJO("minValue", Array(minvalue)) _
                             .RunMethodJO("maxValue", Array(maxvalue)) _
                             .RunMethodJO("autoScale", Array(True)) _
                             .RunMethodJO("axisColor", Array(strokeColor.RunMethod("web", Array(stringAxisColor)))) _
                             .RunMethodJO("tickLabelColor", Array(strokeColor.RunMethod("web", Array(stringTickLabelColor)))) _
                             .RunMethodJO("tickMarkColor", Array(strokeColor.RunMethod("web", Array(stringTickMarkColor)))) _
                             .RunMethodJO("build", Null)
    
    
    Dim anchorPane As JavaObject
    anchorPane.InitializeStatic("javafx.scene.layout.AnchorPane")
    anchorPane.RunMethod("setBottomAnchor", Array(xAxisBottom, 0.0))
    anchorPane.RunMethod("setLeftAnchor", Array(xAxisBottom, axisWidth))
    anchorPane.RunMethod("setRightAnchor", Array(xAxisBottom, axisWidth))
    
    Dim yAxisLeft, yAxisLeftBuilder As JavaObject
    yAxisLeft.InitializeNewInstance("eu.hansolo.fx.charts.Axis", Null)
    yAxisLeftBuilder.InitializeStatic("eu.hansolo.fx.charts.AxisBuilder")

    yAxisLeft = yAxisLeftBuilder.RunMethodJO("create", Array(orientation.GetField("VERTICAL"), position.GetField("LEFT"))) _
                                .RunMethodJO("type", Array(axisType.GetField("LINEAR"))) _
                                .RunMethodJO("prefWidth", Array(prefWidth)) _
                                .RunMethodJO("minValue", Array(0.0)) _
                                .RunMethodJO("maxValue", Array(1000.0)) _
                                .RunMethodJO("autoScale", Array(True)) _
                                .RunMethodJO("axisColor", Array(strokeColor.RunMethod("web", Array(stringAxisColor)))) _
                                .RunMethodJO("tickLabelColor", Array(strokeColor.RunMethod("web", Array(stringTickLabelColor)))) _
                                .RunMethodJO("tickMarkColor", Array(strokeColor.RunMethod("web", Array(stringTickMarkColor)))) _
                                .RunMethodJO("build", Null)
            
    anchorPane.RunMethod("setTopAnchor", Array(yAxisLeft, 0.0))
    anchorPane.RunMethod("setBottomAnchor", Array(yAxisLeft, axisWidth))
    anchorPane.RunMethod("setLeftAnchor", Array(yAxisLeft, 0.0))
    
    Dim grid, gridBuilder As JavaObject
    grid.Initializestatic("eu.hansolo.fx.charts.Grid")
    gridBuilder.InitializeStatic("eu.hansolo.fx.charts.GridBuilder")
    
    Dim gridLinePaintColor As JavaObject
    gridLinePaintColor.InitializeStatic("javafx.scene.paint.Color")
    Dim stringGridLinePaintColor As String = "#384C57"
    
    Dim gridLineDashes(2) As Double
    gridLineDashes(0) = 4
    gridLineDashes(1) = 4
    
    
    grid = gridBuilder.RunMethodJO("create", Array(xAxisBottom, yAxisLeft)) _
                      .RunMethodJO("gridLinePaint", Array(gridLinePaintColor.RunMethod("web", Array(stringGridLinePaintColor)))) _
                      .RunMethodJO("minorHGridLinesVisible", Array(False)) _
                      .RunMethodJO("mediumHGridLinesVisible", Array(False)) _
                      .RunMethodJO("minorVGridLinesVisible", Array(False)) _
                      .RunMethodJO("mediumVGridLinesVisible", Array(False)) _
                      .RunMethodJO("gridLineDashes", Array(gridLineDashes)) _
                      .RunMethodJO("build", Null)
                      
                  
    Log(xySeries1)
    
    
    Dim javaobjectarray As JavaObject
    javaobjectarray.InitializeArray("eu.hansolo.fx.charts.series.XYSeries", Array(xySeries1))
    Dim lineChartPane As JavaObject
    lineChartPane.InitializeNewInstance("eu.hansolo.fx.charts.XYPane", Array(javaobjectarray))
    
    Dim axisjavaobject As JavaObject
    axisjavaobject.InitializeArray("eu.hansolo.fx.charts.Axis", Array(yAxisLeft, xAxisBottom))
    
    chart.InitializeNewInstance("eu.hansolo.fx.charts.XYChart", Array(lineChartPane, grid, axisjavaobject))
    
    'add the chart to Pane1
    Pane1.AddNode(chart,Pane1.Width*0.025,Pane1.Height*0.025,Pane1.Width*0.95,Pane1.Height*0.95)
    
    
End Sub
 
Upvote 0
Top