Reputation: 752
ChartsActivity.kt
import android.support.v7.app.AppCompatActivity
import com.jjoe64.graphview.series.DataPoint
import com.jjoe64.graphview.series.LineGraphSeries
import kotlinx.android.synthetic.main.activity_charts.*
class ChartsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_charts)
val datap = DataPoint[](
DataPoint(0, 1),
DataPoint(5, 1),
DataPoint(6, 1),
DataPoint(5, 6),
DataPoint(2, 8)
)
val series = LineGraphSeries<DataPoint>(datap)
graph1.addSeries(series)
}
}
I am unable to write the correct series in the DataPoint Function. I want to use Kotlin, I have not found any kotlin code for the task.
How can I write the series to get the code working?
Upvotes: 1
Views: 1910
Reputation: 1092
The constructor for Datapoint
requires Double
type.
You can choose to pass Double
or Create another function which accepts Int
(integer) arguments.
fun DP(a: Int, b: Int): DataPoint {
return DataPoint(a.toDouble(), b.toDouble())
}
Then use it as follows
val points = arrayOf( DP(0,1),
DP(5,1),
...
)
val series = LineGraphSeries<DataPoint>(points)
Hope it helps.
Upvotes: 3