B4A Library MPAndroidCharts - Various type of graphs / charts (Latest library V1.22 in post #1)

Johan Schoeman

Expert
Licensed User
Longtime User

I would suggest that for now you use V1.06 (attached). I need to revisit V1.07 as I discovered an error in V1.07 that I need to rethink and correct.....
 

Attachments

  • mpChartLib.xml
    377.5 KB · Views: 177
  • mpChartLib.jar
    363.7 KB · Views: 206

Pencil3

Member
Licensed User
Have a question that I have not been able to figure out on my own. I am trying to use your single line chart to plot points from a db. Have that working almost perfectly, I would like to plot the last 7 entries from the db. When using LineData = 7 the first 7 entries from the db are plotted. How can I set it to plot the last 7 entries?
 

Descartex

Well-Known Member
Licensed User
Longtime User
I think it is not a problem of the library, but of the data that you pass to the chart.
Try to pass only the last 7 data in your database and will surely display correctly as you want.
Regards.
 

Pencil3

Member
Licensed User
Thank you! Very much appreciate the help. You have put me on the right track. I just need to flip the points on the graph now so that the last entry shows on the right side of the graph and first entry on the left side. The graph currently shows the opposite.

SELECT * FROM DATAS ORDER BY ID DESC LIMIT 7;
 

Pencil3

Member
Licensed User
Thanks again jahswani for pointing me in the right direction.

"SELECT * FROM (SELECT * FROM db DATAS ORDER BY ID DESC LIMIT 7) TMP ORDER BY ID ASC"

 

Pencil3

Member
Licensed User
I may be missing something as far as rounding goes. If I try to plot the value "38.5" the graph displays it as "38.00". Another example would be trying to plot the value "9.5". On the graph it shows as "9.0". What am I overlooking?
 

Pencil3

Member
Licensed User
Yes, I did, but it didn't help. For example when I set mlc1.GraphValueDigits = Array As Int(2, 2, 2, 2, 2) and plot the value of "38.5" the value is plotted on the graph as 38.0.

Have you tried setting the GraphValueDigits property?
 

beaker

Member
Licensed User
Yes, I did, but it didn't help. For example when I set mlc1.GraphValueDigits = Array As Int(2, 2, 2, 2, 2) and plot the value of "38.5" the value is plotted on the graph as 38.0.
Hmmm... I thought that would fix your problem. Without seeing the code it's difficult to say. Your values aren't being converted to integers somewhere along the line are they?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Yes, I did, but it didn't help. For example when I set mlc1.GraphValueDigits = Array As Int(2, 2, 2, 2, 2) and plot the value of "38.5" the value is plotted on the graph as 38.0.
Can you upload a small sample project? Will be easier to see what the problem is.
 

Pencil3

Member
Licensed User
Beaker is correct, they are being converted. Trying to figure it out lol.

B4X:
Dim SalValue As List :SalValue.Initialize
            Dim SalDate As List    :SalDate.Initialize
            Dim txtSal As String
            Dim CursorSal As Cursor
                       
            txtSal="SELECT * FROM (SELECT * FROM db DATAS ORDER BY ID DESC LIMIT 14) TMP ORDER BY ID ASC"
            CursorSal=Starter.SQL1.ExecQuery(txtSal)
            For i=0 To CursorSal.RowCount -1
                CursorSal.Position=i
                SalValue.Add(CursorSal.GetInt("A01Sal"))
                SalDate.Add(CursorSal.GetString("A01Date"))
            Next
           
            Dim PSal(SalValue.Size) As Float
            Dim CSal(SalDate.Size) As String
   
            For i=0 To SalValue.Size -1
                PSal(i)=SalValue.Get(i)
                CSal(i)=SalDate.Get(i)
            Next

Can you upload a small sample project? Will be easier to see what the problem is.
 

beaker

Member
Licensed User
Could it be this line that's causing the issue by any chance?
B4X:
SalValue.Add(CursorSal.GetInt("A01Sal"))

This might be better:
B4X:
SalValue.Add(CursorSal.GetDouble("A01Sal"))

or
B4X:
SalValue.Add(CursorSal.GetString("A01Sal"))

I've used GetString and assigned the value to a Float variable for the multiline chart. This worked for me.
 

Pencil3

Member
Licensed User
Success! Thank you beaker! Last night I tried:

B4X:
SalValue.Add(CursorSal.GetString("A01Sal"))

And I received empty string errors.

I just tried your second suggestion of:

B4X:
SalValue.Add(CursorSal.GetDouble("A01Sal"))

And presto, works perfectly. Thank you again.

 

beaker

Member
Licensed User

Good, I'm pleased we found the issue. I think I've avoided the empty string issue by making sure the field(s) can't be empty either by validating the data before committing it to the DB Table and/or making sure the field's NotNull constraint is set to 'True'.

I think this has become off-topic for this thread now
 

peacemaker

Expert
Licensed User
Longtime User
HI, All

It's very interesting lib, trying the b4aMPMultiLineChartV5 sample.
But maybe any help, if it's possible: if we need to combine several lines on a single chart - the first line is the main one, making the max chart Y-size - the scale for whole the chart. And for the best data comparision at the same time - all next lines must be added within the scale of the first main line.
If main line values, say, are 600 ... 800 (Min1 ... Max1), but others are 0...5, or 0...100 - they must be scaled: * (Max1 - Min1) to fill the whole chart Y-size. But the visible values of the scaled lines should be shown real, without scaling.
Is it possible ?

See the screenshots:
1) the main line is red, the view should be as "0.28" (all lines maximally expanded by Y-axle)

2) green line value scaled is on "correctly scaled" = 379, but with value marker is needed as from "real values", really it's value = 50.

So, task is to show all lines maximally expanded by Y-axle, with real values on the markers.
 

Attachments

  • correctly scaled.png
    170.4 KB · Views: 201
  • real values.png
    166.6 KB · Views: 210
  • 0.28.png
    177.7 KB · Views: 204
Last edited:

peacemaker

Expert
Licensed User
Longtime User
I mean in the prev post - it would be super, if to just add mlc1.Chart_x_Alias like mlc1.Chart_x_Data. And draw using _Data, but _Alias for showing on the marker.
This will allow to combine not only digit line charts, but any event lines.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…