#Region Project Attributes
#ApplicationLabel: mpAndroidMultiLineChart
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#AdditionalJar: mpChartLib
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Dim ctx As JavaObject
Dim lineChart As JavaObject
Dim Entry As JavaObject
Dim lineDataSet As JavaObject
Dim lineData As JavaObject
Dim Legend As JavaObject
Dim MarkerView As JavaObject
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Dim x As XmlLayoutBuilder
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
ctx.InitializeContext
lineChart.InitializeNewInstance("com.github.mikephil.charting.charts.LineChart", Array(ctx))
Dim e As Object = lineChart.CreateEvent("com.github.mikephil.charting.listener.OnChartValueSelectedListener", "line_clicked", False)
lineChart.RunMethod("setOnChartValueSelectedListener", Array(e))
lineChart.RunMethod("setDrawGridBackground", Array(True))
lineChart.RunMethod("setDescription", Array(""))
lineChart.RunMethod("setHighlightEnabled", Array(True))
lineChart.RunMethod("setTouchEnabled", Array(True))
lineChart.RunMethod("setDragEnabled", Array(True))
lineChart.RunMethod("setScaleEnabled", Array(True))
lineChart.RunMethod("setPinchZoom", Array(True))
Legend.InitializeNewInstance("com.github.mikephil.charting.components.Legend", Null)
Legend = lineChart.RunMethod("getLegend", Null)
Dim Legendposition As JavaObject
Legendposition.InitializeStatic("com.github.mikephil.charting.components.Legend.LegendPosition")
'RIGHT_OF_CHART, RIGHT_OF_CHART_CENTER, RIGHT_OF_CHART_INSIDE, LEFT_OF_CHART, LEFT_OF_CHART_CENTER, LEFT_OF_CHART_INSIDE, BELOW_CHART_LEFT, BELOW_CHART_RIGHT, BELOW_CHART_CENTER, PIECHART_CENTER
Legend.RunMethod("setPosition", Array(Legendposition.GetField("BELOW_CHART_CENTER")))
Legend.RunMethod("setXEntrySpace", Array(7.0f))
Dim Legendform As JavaObject
'SQUARE, CIRCLE, LINE
Legendform.InitializeStatic("com.github.mikephil.charting.components.Legend.LegendForm")
Legend.RunMethod("setForm", Array(Legendform.GetField("SQUARE")))
'LEFT_TO_RIGHT, RIGHT_TO_LEFT
Dim Legenddirection As JavaObject
Legenddirection.InitializeStatic("com.github.mikephil.charting.components.Legend.LegendDirection")
Legend.RunMethod("setDirection", Array(Legenddirection.GetField("LEFT_TO_RIGHT")))
Legend.RunMethod("setTextSize", Array(14.0f))
Legend.RunMethod("setTextColor", Array(Colors.Black))
Dim xvals As List
xvals.Initialize
For i = 0 To 360
xvals.Add(i & "")
Next
Dim dataSets As List
dataSets.Initialize
Dim numOfLineCharts As Int = 7
For z = 0 To numOfLineCharts - 1
Dim values As List
values.Initialize
Dim extra As Int = 0
extra = z * 360 / numOfLineCharts
For i = 0 To 360
values.Add(Entry.InitializeNewInstance("com.github.mikephil.charting.data.Entry", Array((Sin(2 * cPI * (i + extra) / 360)).As(Float), i)))
Next
lineDataSet.InitializeNewInstance("com.github.mikephil.charting.data.LineDataSet", Array(values, "D " & (z+1)))
lineDataSet.RunMethod("setLineWidth", Array(2.5f))
lineDataSet.RunMethod("setCircleSize", Array(1.0f))
' lineDataSet.RunMethod("setDrawCircles", Array(False))
Dim color As Int = Colors.ARGB(Rnd(255, 256), Rnd(100,256),Rnd(100,256), Rnd(100, 256))
lineDataSet.RunMethod("setColor", Array(color))
lineDataSet.RunMethod("setCircleColor", Array(color))
lineChart.RunMethod("notifyDataSetChanged", Null)
dataSets.add(lineDataSet)
Next
dataSets.get(0).As(JavaObject).RunMethod("enableDashedLine", Array(10.0f, 10.0f, 0.0f))
'USE THE FOLLOWING AS IN THE ABOVE LINE OF CODE TO SET DIFFERENT ATTRIBUTES FOR EACH LINEDATASET
' lineDataSet.RunMethod("setColor", Array(Colors.Blue))
' lineDataSet.RunMethod("setCircleColor", Array(Colors.Blue))
' lineDataSet.RunMethod("setLineWidth", Array(2.0f))
' lineDataSet.RunMethod("setCircleSize", Array(2.0f))
' lineDataSet.RunMethod("setDrawCircleHole", Array(True))
' lineDataSet.RunMethod("setValueTextSize", Array(9.0f))
' lineDataSet.RunMethod("setFillAlpha", Array(200))
' lineDataSet.RunMethod("setFillColor", Array(Colors.Black))
' lineDataSet.RunMethod("setDrawCubic", Array(True))
' lineDataSet.RunMethod("setCubicIntensity", Array(1.0f))
dataSets.get(1).As(JavaObject).RunMethod("setHighLightColor",Array(Colors.Red))
dataSets.get(1).As(JavaObject).RunMethod("setHighlightLineWidth", Array(3.0f))
lineData.InitializeNewInstance("com.github.mikephil.charting.data.LineData", Array(xvals, dataSets))
lineChart.RunMethod("setData", Array(lineData))
x.LoadXmlLayout(Null, "custom_marker_view_1")
Dim ResourceId As Int
ResourceId = x.GetResourceId("layout", "custom_marker_view_1")
MarkerView.InitializeNewInstance("com.github.mikephil.charting.components.MyMarkerView", Array(ctx, ResourceId))
MarkerView.RunMethod("setNumberOfDigits", Array(3))
lineChart.RunMethod("setMarkerView", Array(MarkerView))
lineChart.RunMethod("animateXY", Array(3000, 3000))
Dim Xaxis As JavaObject
Xaxis.InitializeNewInstance("com.github.mikephil.charting.components.XAxis", Null)
Xaxis = lineChart.RunMethod("getXAxis", Null)
Xaxis.RunMethod("setTextSize", Array(12.0f))
Xaxis.RunMethod("setTextColor", Array(Colors.Red))
Xaxis.RunMethod("setDrawGridLines", Array(True))
Xaxis.RunMethod("setDrawAxisLine", Array(True))
Xaxis.RunMethod("setXaxisTextAngle", Array(45.0f))
Dim xAxisPosition As JavaObject
' 'TOP, BOTTOM, BOTH_SIDED, TOP_INSIDE, BOTTOM_INSIDE
xAxisPosition.InitializeStatic("com.github.mikephil.charting.components.XAxis.XAxisPosition")
Xaxis.RunMethod("setPosition", Array(xAxisPosition.GetField("BOTTOM")))
Dim yLeftAxis, yRightAxis As JavaObject
yLeftAxis.InitializeNewInstance("com.github.mikephil.charting.components.YAxis", Null)
yRightAxis.InitializeNewInstance("com.github.mikephil.charting.components.YAxis", Null)
yLeftAxis = lineChart.RunMethod("getAxisLeft", Null)
yRightAxis = lineChart.RunMethod("getAxisRight", Null)
yLeftAxis.RunMethod("removeAllLimitLines", Null)
' yLeftAxis.RunMethod("addLimitLine", Array(ll1))
' yLeftAxis.RunMethod("addLimitLine", Array(ll2))
yLeftAxis.RunMethod("setAxisMaxValue", Array(1.2f))
yLeftAxis.RunMethod("setAxisMinValue", Array(-1.2f))
yLeftAxis.RunMethod("setStartAtZero", Array(True))
yLeftAxis.RunMethod("enableGridDashedLine", Array(10.0f, 10.0f, 0.0f))
yLeftAxis.RunMethod("setTextColor", Array(Colors.DarkGray))
yLeftAxis.RunMethod("setDrawLimitLinesBehindData", Array(True))
yRightAxis.RunMethod("setAxisMaxValue", Array(1.2f))
yRightAxis.RunMethod("setAxisMinValue", Array(-1.2f))
yRightAxis.RunMethod("setStartAtZero", Array(True))
yRightAxis.RunMethod("enableGridDashedLine", Array(10.0f, 10.0f, 0.0f))
yRightAxis.RunMethod("setTextColor", Array(Colors.DarkGray))
yRightAxis.RunMethod("setDrawLimitLinesBehindData", Array(True))
Dim valueFormatter As JavaObject
valueFormatter.InitializeNewInstance("com.github.mikephil.charting.utils.MyValueFormatter", Null)
valueFormatter.RunMethod("setNumberOfDigits", Array(3))
yLeftAxis.RunMethod("setValueFormatter", Array(valueFormatter))
yRightAxis.RunMethod("setValueFormatter", Array(valueFormatter))
lineChart.RunMethodJO("getAxisRight", Null).RunMethod("setEnabled", Array(True))
'Linear, EaseInQuad, EaseOutQuad, EaseInOutQuad, EaseInCubic, EaseOutCubic, EaseInOutCubic, EaseInQuart, EaseOutQuart, EaseInOutQuart, EaseInSine, EaseOutSine, EaseInOutSine, EaseInExpo, EaseOutExpo, EaseInOutExpo, EaseInCirc, EaseOutCirc, EaseInOutCirc, EaseInElastic, EaseOutElastic, EaseInOutElastic, EaseInBack, EaseOutBack, EaseInOutBack, EaseInBounce, EaseOutBounce, EaseInOutBounce
' Dim EasingOption As JavaObject
' EasingOption.InitializeStatic("com.github.mikephil.charting.animation.Easing.EasingOption")
' lineChart.RunMethod("animateY", Array(2000, EasingOption.GetField("EaseInOutBounce")))
Activity.AddView(lineChart, 0, 5%y, 100%x, 80%y)
Activity.Invalidate
'' Dim limitLine As JavaObject
'' limitLine.InitializeNewInstance("com.github.mikephil.charting.components.LimitLine", Array(10.0f, "Index 10"))
'' limitLine.RunMethod("setLineWidth", Array(4.0f))
'' limitLine.RunMethod("enableDashedLine", Array(10.0f, 10.0f, 0.0f))
'
'' Dim LimitLabelPosition As JavaObject
'' LimitLabelPosition.InitializeStatic("com.github.mikephil.charting.components.LimitLine.LimitLabelPosition")
'' limitLine.RunMethod("setLabelPosition", Array(LimitLabelPosition.GetField("RIGHT_BOTTOM")))
'' limitLine.RunMethod("setTextSize", Array(10.0f))
'' Dim ll1 As JavaObject
'' ll1.InitializeNewInstance("com.github.mikephil.charting.components.LimitLine", Array(130.0f, "Upper Limit"))
'' ll1.RunMethod("setLineWidth", Array(4.0f))
'' ll1.RunMethod("enableDashedLine", Array(10.0f, 10.0f, 0.0f))
'' Dim ll1Position As JavaObject
'' ll1Position.InitializeStatic("com.github.mikephil.charting.components.LimitLine.LimitLabelPosition")
'' ll1.RunMethod("setLabelPosition", Array(ll1Position.GetField("RIGHT_TOP")))
'' ll1.RunMethod("setTextSize", Array(10.0f))
''
'' Dim ll2 As JavaObject
'' ll2.InitializeNewInstance("com.github.mikephil.charting.components.LimitLine", Array(-30.0f, "Lower Limit"))
'' ll2.RunMethod("setLineWidth", Array(4.0f))
'' ll2.RunMethod("enableDashedLine", Array(10.0f, 10.0f, 0.0f))
'' Dim ll1Position As JavaObject
'' ll1Position.InitializeStatic("com.github.mikephil.charting.components.LimitLine.LimitLabelPosition")
'' ll2.RunMethod("setLabelPosition", Array(ll1Position.GetField("RIGHT_BOTTOM")))
'' ll2.RunMethod("setTextSize", Array(10.0f))
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub line_clicked_Event (MethodName As String, Args() As Object) As Object
If MethodName = "onValueSelected" Then
Log(Args(0)) 'Logs the xIndex and the yValue - index starts at 0
Log(Args(2)) 'Logs the xIndex and the DataSetIndex - inxdex starts at 0
Log(" ")
Else
'do nothing
End If
Return Null
End Sub