Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

36 changes: 36 additions & 0 deletions app/src/main/java/info/appdev/chartexample/custom/MyMarkerView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package info.appdev.chartexample.custom

import android.annotation.SuppressLint
import android.content.Context
import android.widget.TextView
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.data.CandleEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.highlight.Highlight
import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Utils
import info.appdev.chartexample.R

/**
* Custom implementation of the MarkerView.
*/
@SuppressLint("ViewConstructor")
class MyMarkerView(context: Context?, layoutResource: Int) : MarkerView(context, layoutResource) {
private val tvContent: TextView = findViewById(R.id.tvContent)

// runs every time the MarkerView is redrawn, can be used to update the
// content (user-interface)
override fun refreshContent(e: Entry, highlight: Highlight?) {
if (e is CandleEntry) {
tvContent.text = Utils.formatNumber(e.high, 0, true)
} else {
tvContent.text = Utils.formatNumber(e.y, 0, true)
}

super.refreshContent(e, highlight)
}

override fun getOffset(): MPPointF {
return MPPointF(-(width / 2).toFloat(), -height.toFloat())
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package info.appdev.chartexample.custom

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Typeface
import android.widget.TextView
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.highlight.Highlight
import com.github.mikephil.charting.utils.MPPointF
import info.appdev.chartexample.R
import java.text.DecimalFormat

/**
* Custom implementation of the MarkerView.
*/
@SuppressLint("ViewConstructor")
class RadarMarkerView(context: Context, layoutResource: Int) : MarkerView(context, layoutResource) {
private val tvContent: TextView = findViewById(R.id.tvContent)
private val format = DecimalFormat("##0")

init {
tvContent.setTypeface(Typeface.createFromAsset(context.assets, "OpenSans-Light.ttf"))
}

// runs every time the MarkerView is redrawn, can be used to update the
// content (user-interface)
override fun refreshContent(e: Entry, highlight: Highlight?) {
tvContent.text = String.format("%s %%", format.format(e.y.toDouble()))

super.refreshContent(e, highlight)
}

override fun getOffset(): MPPointF {
return MPPointF(-(width / 2).toFloat(), (-height - 10).toFloat())
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package info.appdev.chartexample.custom

import android.annotation.SuppressLint
import android.content.Context
import android.widget.TextView
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.data.BarEntry
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.highlight.Highlight
import com.github.mikephil.charting.utils.MPPointF
import com.github.mikephil.charting.utils.Utils
import info.appdev.chartexample.R

/**
* Custom implementation of the MarkerView.
*/
@Suppress("unused")
@SuppressLint("ViewConstructor")
class StackedBarsMarkerView(context: Context?, layoutResource: Int) : MarkerView(context, layoutResource) {
private val tvContent: TextView = findViewById(R.id.tvContent)

// runs every time the MarkerView is redrawn, can be used to update the
// content (user-interface)
override fun refreshContent(entry: Entry, highlight: Highlight) {
if (entry is BarEntry) {

if (entry.yVals != null) {
// draw the stack value
tvContent.text = Utils.formatNumber(entry.yVals!![highlight.stackIndex], 0, true)
} else {
tvContent.text = Utils.formatNumber(entry.y, 0, true)
}
} else {
tvContent.text = Utils.formatNumber(entry.y, 0, true)
}

super.refreshContent(entry, highlight)
}

override fun getOffset(): MPPointF {
return MPPointF(-(width / 2).toFloat(), -height.toFloat())
}
}

This file was deleted.

33 changes: 33 additions & 0 deletions app/src/main/java/info/appdev/chartexample/custom/XYMarkerView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package info.appdev.chartexample.custom

import android.annotation.SuppressLint
import android.content.Context
import android.widget.TextView
import com.github.mikephil.charting.components.MarkerView
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.formatter.IAxisValueFormatter
import com.github.mikephil.charting.highlight.Highlight
import com.github.mikephil.charting.utils.MPPointF
import info.appdev.chartexample.R
import java.text.DecimalFormat

/**
* Custom implementation of the MarkerView.
*/
@SuppressLint("ViewConstructor")
class XYMarkerView(context: Context?, private val xAxisValueFormatter: IAxisValueFormatter) : MarkerView(context, R.layout.custom_marker_view) {
private val tvContent: TextView = findViewById(R.id.tvContent)

private val format: DecimalFormat = DecimalFormat("###.0")

// runs every time the MarkerView is redrawn, can be used to update the content (user-interface)
override fun refreshContent(e: Entry, highlight: Highlight?) {
tvContent.text = String.format("x: %s, y: %s", xAxisValueFormatter.getFormattedValue(e.x, null), format.format(e.y.toDouble()))

super.refreshContent(e, highlight)
}

override fun getOffset(): MPPointF {
return MPPointF(-(width / 2).toFloat(), -height.toFloat())
}
}
Loading