B4J Question Passing data from .csv to Scatter Chart of jChart

Cal4th

Member
I am trying to pass x and y points from .csv files to plot them in the scatter chart of jChart library.
Code:
B4X:
    Xc = File.ReadList(File.DirApp, "naca0015x.csv")
    Yc = File.ReadList(File.DirApp, "naca0015y.csv")
Dim Series As XYSeries
    Series.Initialize("Original Profile")
    For i = 0 To Xc.Size - 1 ' Xc and Yc are the same size
        Dim x As Double = Xc.Get(i) '(error  occurs in this line)
        Dim y As Double = Yc.Get(i)
        Series.Add(x, y)
    Next
    ScatterChart.AddSeries(Series)

The error that appears in the log is the following:

Error occurred on line: (Line indicated in the code comments) (Main)
java.lang.NumberFormatException: For input string: "1"
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your file includes the UTF8 BOM.
It is an extra character at the beginning of the text.

You can either remove it yourself with Notepad++ or skip it:
B4X:
Xc = File.ReadList(File.DirApp, "naca0015x.csv")
 Yc = File.ReadList(File.DirApp, "naca0015y.csv")
Dim s As String = Xc.Get(0)
Xc.Put(0, s.Substring(1))
s = Yc.Get(0)
Yc.Put(0, s.SubString(1))
 
Upvote 0
Top