B4J Question [Solved] jCharts with OpenJDK 11 - can't display negative values on Stacked Bar Chart

Chris2

Active Member
Licensed User
Longtime User
I can't get the Stacked Bar Charts of jCharts to display negative values when running with java 11 (OpenJDK 11). It works OK under Java 8.

To test it I've gone back to the original examples posted by Informatix (Charts2 from https://www.b4x.com/android/forum/threads/jcharts.71975/).

I changed a couple of the values in the XYSeries to be negative;
B4X:
Dim Series2 As XYSeries
	Series2.Initialize("Oreo")
	Series2.Add("Feb",40)
	Series2.Add("Mar",38)
	Series2.Add("Apr",39)
	Series2.Add("May",36)
	Series2.Add("Jun",-33)
	Series2.Add("Jul",-32)
	Series2.Add("Aug",28)
	Series2.Add("Sept",29)
	Series2.Add("Oct",27)
	Series2.Add("Nov",25)
	Series2.Add("Dec",20)
	BarChart.AddAllSeries(Array As XYSeries(Series1, Series2))

and ran it first with with the javac.exe in Tools>Configure Paths set to Java 8, then to openJDK 11. The screen shots attached show the output, with Java 8 showing the negative values correctly (right image) but Open Java 11 missing them off (left image).

Am I missing something here, or could this be an issue in the jCharts library or OpenJFX itself?
 
Last edited:

Chris2

Active Member
Licensed User
Longtime User
Hi Erel
Yes it does, you can set AutoRanging false and manually set the lower bound of the yaxis.
I'd already seen that stackoverflow page and have had a play with setting AutoRanging to false & manually setting the upper & lower bounds, but it makes no difference to this issue.

Interestingly, even with Open Java 11, the standard bar chart (not stacked), and the line chart will display negative numbers correctly. It seems to be an issue with the Stacked Bar Chart only.
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
After digging around I've found this - https://github.com/javafxports/openjdk-jfx/issues/477, which seems to suggest that someone else has spotted the same issue and reported it as a bug in open javafx.
I'm wondering if I can use in-line Java to correct the issue with the corrected code in that post
B4X:
'....
// ok
    StackedBarChart<String, Number> barChart2 = new StackedBarChart<String, Number>(xAxis, yAxis){
      @Override protected void seriesChanged(ListChangeListener.Change<? extends Series> c) {}      
    }; 
'....

I am a bit out of my depth here though and don't know Java at all.
Should I be able use in-line java to correct this issue? If so, can someone please suggest how?

I've looked at the in-line java examples in the forums but can't figure it out. At present I've got
B4X:
#If JAVA
       import javafx.scene.chart.StackedBarChart;
      @Override protected void seriesChanged(ListChangeListener.Change<? extends Series> c) ;
#End If

with the following in the sub that builds the chart
B4X:
Dim jo As JavaObject = Me
jo.RunMethod("StackedBarChart", Null)
BarChart.AddSeries(Series1)

But I get the following error when compiling;
Compiling generated Java code. Error
B4J line: 282
End Sub
src\b4j\example\main.java:759: error: package ListChangeListener does not exist
@override protected void seriesChanged(ListChangeListener.Change<? extends Series> c); //{}
^
1 error
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
It's easy to do the changes on my side so here's the fix. I can't test it so please report whether the problem is solved.
 

Attachments

  • jCharts v1.21.zip
    63.5 KB · Views: 396
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…