# How to graph formula in kotlin using graphview

**URL:** <https://discuss.kotlinlang.org/t/how-to-graph-formula-in-kotlin-using-graphview/12399>\
**Category:** Uncategorized\
**Created:** [April 18, 2019, 11:50pm UTC](https://discuss.kotlinlang.org/t/how-to-graph-formula-in-kotlin-using-graphview/12399 "2019-04-18T23:50:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![royer11](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@royer11](https://discuss.kotlinlang.org/u/royer11)\
**Post date:** [April 18, 2019, 11:50pm UTC](https://discuss.kotlinlang.org/t/how-to-graph-formula-in-kotlin-using-graphview/12399/1 "2019-04-18T23:50:43Z")

</div>

I have imported the GraphView library and since its documentation is in good java, it is difficult for me to transcribe it to kotlin, my goal is to **graph statistical distributions** and for this I have the following formula:  
[Link view image reference](https://i.stack.imgur.com/aEcvS.png)  
**activity\_hipotesismedia.xml**

```
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".Hipotesismedia1Activity">

    <com.jjoe64.graphview.GraphView
            android:id="@+id/plot"
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" 
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

</android.support.constraint.ConstraintLayout>

```

**Hipotesismedia1Activity.kt**

```
class Hipotesismedia1Activity : AppCompatActivity() {
lateinit var series1: LineGraphSeries<DataPoint>

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_hipotesismedia1)

    series1 = LineGraphSeries<DataPoint>()
    var x:Double = 0.0
    var y:Double = 0.0
    val sigma = 2.5
    val media = 300.0

    for ( i in 0..295){
        x += i.toDouble()
        y = Math.exp(-((x-media).pow(2))/(sigma* sqrt(2* PI)))/(sigma* sqrt(2* PI))
        series1.appendData(DataPoint(x,y),true,40)
    }
    plot.viewport.setMaxX(350.0)
    plot.addSeries(series1)
    plot.viewport.isXAxisBoundsManual = true
    plot.viewport.isScalable = true
    plot.viewport.isScrollable = true
 }
}

```

The graph I have is a triangular line, can you please try to correct my error?
