iOS Code Snippet Chart with JS (WebView)

Hi,

attached you can find a little project which shows the basic integration of a BarChart with Chart.js.

Jan

barchart-png.51654

More examples:
 

Attachments

Last edited:
AweSome! Charts are one of the basic needs of a simple app. They look beautifulş . Thanks Jan for another help to b4i community.
 
Hi,

attached you can find a little project which shows the basic integration of a BarChart with Chart.js.

Jan

barchart-png.51654
Dear Jan,

There is a little problem with update data i think. Lets say we updated the data with a higher number of datasets ( lets say we had 5 data for the graph but later we updated it to 10 data for the graph.) this is no problem. The graph adds the new datas and there are a total of 10 points on the graph.. But if we update the data with less number of datasets ( lets say we had 10 points at first but we want to update to 5 points ) first 5 points updates to graph but there are still 10 points on the graph and last 5 data is from the previous dataset(from 6 to 10 ) so it makes problem.
 
Hi,

ist very simple: just clean the data array before you add new data:
Code: Copy
JS($"JSBarChart.data.datasets[0].data = [];"$,W)

But note: When you change the number of data, you also have to take care about the labels, backgroundColor and borderColor.

Jan
 
Hi,

ist very simple: just clean the data array before you add new data:
Code: Copy
JS($"JSBarChart.data.datasets[0].data = [];"$,W)

But note: When you change the number of data, you also have to take care about the labels, backgroundColor and borderColor.

Jan
This results with this :

other half of the data still shows but without any line
IMG_9086.png
 
Can you post the relevant code?
Code: Copy
    JS($"JSBarChart.data.datasets[0].data = [];"$,W)
    'JS($"JSBarChart.data.labels[0].data = [];"$,W)
'    JS("JSBarChart.reset();",w)
'    JS("JSBarChart.update();",w)


    For i = 0 To Data.Size -1
        JS($"JSBarChart.data.datasets[0].data[${i}] = ${Data.Get(i)};"$,W)
        JS($"JSBarChart.data.labels[${i}] = ${Data.Get(i)};"$,W)
    Next
   
    JS("JSBarChart.update();",w)
    Data.Clear


I call this with :

Code: Copy
UpdateData(Array(listegrafik.Get(0),listegrafik.Get(1),listegrafik.Get(2),listegrafik.Get(3),listegrafik.Get(4),listegrafik.Get(5),listegrafik.Get(6),listegrafik.Get(7),listegrafik.Get(8),listegrafik.Get(9),listegrafik.Get(10),listegrafik.Get(11),listegrafik.Get(12),listegrafik.Get(13),listegrafik.Get(14)))

it works good but when switching to a smaller dataset this problem happens

Code: Copy
UpdateData(Array(listegrafik.Get(0),listegrafik.Get(1),listegrafik.Get(2),listegrafik.Get(3),listegrafik.Get(4),listegrafik.Get(5),listegrafik.Get(6)))
i also tried the commented code blocks at the begining with no luck:
 
Dear Jan. Can we use this code snipper with b4a without using b4a library for this _? Just to show with the webview ?
I tried it, I changed the nativeobject to javaobject and it works. But for the updatedata, a line is giving an error under sub js

Code: Copy
NaObj.RunMethod("stringByEvaluatingJavaScriptFromString:", Array(Script))

this gives error :

java.lang.RuntimeException: Method: stringByEvaluatingJavaScriptFromString: not found in: android.webkit.WebView

probably this is for ios webview , for android we have to change this to something but i couldnt find .
 
Hi,

change the JS sub to the following:

Code: Copy
Sub JS (Script As String, WebV As WebView)
    WebV.Loadurl("javascript:" & Script)
End Sub

Attached you can find a B4A demo project.

Jan
 

Attachments

Hi,

change the JS sub to the following:

Code: Copy
Sub JS (Script As String, WebV As WebView)
    WebV.Loadurl("javascript:" & Script)
End Sub

Attached you can find a B4A demo project.

Jan

Dear Jan ,

I have a little question with the b4i code.
JS($"JSBarChart.data.labels[1] = "xxx";"$,WebViewairports)

instead of xxx how can i use list.get(0) . I am having trouble with $'s
 

Attachments

Back
Top