B4A Library Google Charts

This library will allow you to create nice charts using the Google Charts API.

Requirements:

1- B4A 4.3x.

2- The CloudPrint library.

3- The WebViewExtras library.

4- Internet connection.

5- Copy the GoogleCharts.xml and GoogleCharts.jar to your additional libraries directory.


Usage:
B4X:
'Initialize the library
Private gChart As GoogleCharts

gChart.Initialize(ChartView, Me, "Chart", True)

gChart.AddOnlineCustomFontToChart = "Roboto:100" 'The font name is CASE SENSITIVE.

gChart.PieChartTitle = "My daily activities (hours)"
gChart.PieChartTitleStyle("purple", "roboto", 30, False, True)
gChart.PieChartLegend("right", "blue", "roboto", 20, False, False)
gChart.PieChart3D = True
gChart.PieChartSliceText = "percentage"
gChart.PieChartSliceLabelAndValue("Work", 11)
gChart.PieChartSliceLabelAndValue("Eat", 2)

gChart.PieChartSliceLabelAndValue("Commute", 2)
gChart.PieChartSliceLabelAndValue("Watch TV", 2)
gChart.PieChartSliceLabelAndValue("Sleep", 7)
gChart.PieChartSetSliceOffset("Watch TV", 3)


gChart.ShowPieChart

The charts included are:

- Pie (3D and Donut).
- Bar.
- Combo (Bar, Area, Stepped Area, Line).
- Histogram.
- Scatter.
- Bubble.
- Geo.


Features:

- Use custom fonts (Online fonts via Google Fonts or local).
- Save charts.
- Print charts.


For more details about the use of this library please check the attached project.

You can try the attached APK if you just want to see what the library can do.
 

Attachments

  • GoogleCharts_Lib_1.0.zip
    23 KB · Views: 508
  • GoogleChartsSampleProject.zip
    61.6 KB · Views: 497
  • GoogleChartsSample.apk
    214.9 KB · Views: 413

iamfanghan

Member
Licensed User
Longtime User
Take a look at the below link, Google line chart displays vertical and horizontal gridlines. The rest of us have been accustomed to challenge someone like you to figure it out because of your vast knowledge. We have been spoiled with powerhouses like you. With or without offering that option, your lib is still very useful and deserves great accolade.
https://developers.google.com/chart/interactive/docs/gallery/linechart
Good day, as from the link, can you briefly explain how to use the curveType:function in B4A? I'm new to this and i always got in a confusion between Java codes and B4A codes :oops:
 

iamfanghan

Member
Licensed User
Longtime User
It would have been nice if the graph generated by NJDude's lib displays vertical gridlines that intersect the X value axis. It would add better readability for the chart. See the chart that is generated by the lib and the other chart where I manually added the vertical gridlines.
Sir, how did you create the SavedChart.png chart? Can i have a look at the codes?
 

iamfanghan

Member
Licensed User
Longtime User
If you are using this library, set the curve type to "function":
B4X:
gChart.ComboChartDefaultCurveType = "function"

If you want an example, check the attached project to THIS post.
Thank you sir. However, is it possible to do so with ScatterChart?
 

iamfanghan

Member
Licensed User
Longtime User
Have you seen the example I attached to the first post?
Yes sir, for ScatterChart the polynomial function was used. Wonder if there is any other function available?
By the way, sir, if you would, is it possible for 2 values in 1 column?

means at x, y=15
x, y=-5

gChart.ComboChartSetColumnValues(x, comboData5)
 

Croïd

Active Member
Licensed User
Longtime User
Hi Njude and big thank for you lib

It is possible add "RadarChart (spider web chart)" ? maybe it's not easy !

https://github.com/PhilJay/MPAndroidChart

spider.png
 

incendio

Well-Known Member
Licensed User
Longtime User
Thanks for the library.

Just tested on the apk, clicked different charts, but after clicked for a few times, chart didn't showed, just blank screen.

Restarted app again fix the problem, but after a few clicked again, same problem came, blank screen.
 

Mahares

Expert
Licensed User
Longtime User
@Mashiane:
I created a small project for you using NJDude Google Charts Lib 100 that shows you how to have a line graph with 2 Y axes plotted versus the X axis. I generate a small SQLite table from which the data is plotted. I hope it helps.
Thank you
 

Attachments

  • GoogleChartsUsingNJDudeLib100SentToMachiane.zip
    19.7 KB · Views: 185

TheMightySwe

Active Member
Licensed User
Longtime User
java.io.FileNotFoundException: /mnt/sdcard/Android/data/se.iqpd.checkout.plus/files/NJDudeTempChart.png: open failed: ENOENT (No such file or directory)

Hi, am i lacking some kind of permission?

I trying to save the generated Graph inside...

B4X:
Sub Chart_ChartGenerated_Response

    ProgressDialogHide
    Chart.SaveChart(FileHandling.CheckoutFolder & "/Charts/", "SavedChart.png")

End Sub
 
Top