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
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import com.github.mikephil.charting.listener.OnChartValueSelectedListener
import com.github.mikephil.charting.utils.Fill
import com.github.mikephil.charting.utils.MPPointF
import info.appdev.chartexample.DataTools.Companion.getValues
import info.appdev.chartexample.custom.DayAxisValueFormatter
import info.appdev.chartexample.custom.MyAxisValueFormatter
import info.appdev.chartexample.formatter.DayAxisValueFormatter
import info.appdev.chartexample.formatter.MyAxisValueFormatter
import info.appdev.chartexample.custom.XYMarkerView
import info.appdev.chartexample.notimportant.DemoBase

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import androidx.core.net.toUri
/**
* Demonstrates the use of charts inside a ListView. IMPORTANT: provide a
* specific height attribute for the chart inside your ListView item
*
* @author Philipp Jahoda
*/
class ListViewBarChartActivity : DemoBase() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class ListViewMultiChartActivity : DemoBase() {
}

/** adapter that supports 3 different item types */
private class ChartDataAdapter(context: Context, objects: MutableList<ChartItem?>) : ArrayAdapter<ChartItem?>(context, 0, objects) {
private class ChartDataAdapter(context: Context, objects: MutableList<ChartItem?>) : ArrayAdapter<ChartItem>(context, 0, objects) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
return getItem(position)!!.getView(position, convertView, context)
return getItem(position)!!.getView(position, convertView, context)!!
}

override fun getItemViewType(position: Int): Int {
// return the views type
val ci = getItem(position)
return if (ci != null) ci.getItemType() else 0
return if (ci != null) ci.itemType else 0
}

override fun getViewTypeCount(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import com.github.mikephil.charting.interfaces.datasets.IBarDataSet
import com.github.mikephil.charting.listener.OnChartValueSelectedListener
import com.github.mikephil.charting.utils.ColorTemplate
import info.appdev.chartexample.DataTools.Companion.getValues
import info.appdev.chartexample.custom.MyAxisValueFormatter
import info.appdev.chartexample.custom.MyValueFormatter
import info.appdev.chartexample.formatter.MyAxisValueFormatter
import info.appdev.chartexample.formatter.MyValueFormatter
import info.appdev.chartexample.notimportant.DemoBase

class StackedBarActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {
Expand Down

This file was deleted.

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

import android.graphics.Canvas
import android.graphics.Paint
import com.github.mikephil.charting.interfaces.datasets.IScatterDataSet
import com.github.mikephil.charting.renderer.scatter.IShapeRenderer
import com.github.mikephil.charting.utils.Utils
import com.github.mikephil.charting.utils.ViewPortHandler

/**
* Custom shape renderer that draws a single line.
*/
class CustomScatterShapeRenderer : IShapeRenderer {
override fun renderShape(
canvas: Canvas, dataSet: IScatterDataSet, viewPortHandler: ViewPortHandler?,
posX: Float, posY: Float, renderPaint: Paint
) {
val shapeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeSize()) / 2f

canvas.drawLine(
posX - shapeHalf,
posY - shapeHalf,
posX + shapeHalf,
posY + shapeHalf,
renderPaint
)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.appdev.chartexample.custom
package info.appdev.chartexample.formatter

import com.github.mikephil.charting.charts.BarLineChartBase
import com.github.mikephil.charting.components.AxisBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.appdev.chartexample.custom
package info.appdev.chartexample.formatter

import com.github.mikephil.charting.components.AxisBase
import com.github.mikephil.charting.formatter.IAxisValueFormatter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.appdev.chartexample.custom
package info.appdev.chartexample.formatter

import com.github.mikephil.charting.formatter.IFillFormatter
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider
Expand All @@ -10,4 +10,4 @@ class MyFillFormatter(private val fillPos: Float) : IFillFormatter {
// your logic could be here
return fillPos
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.appdev.chartexample.custom
package info.appdev.chartexample.formatter

import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.formatter.IValueFormatter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package info.appdev.chartexample.custom
package info.appdev.chartexample.formatter

import com.github.mikephil.charting.components.AxisBase
import com.github.mikephil.charting.formatter.IAxisValueFormatter
Expand Down
113 changes: 0 additions & 113 deletions app/src/main/java/info/appdev/chartexample/fragments/BarChartFrag.java

This file was deleted.

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

import android.graphics.Typeface
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture
import com.github.mikephil.charting.listener.OnChartGestureListener
import info.appdev.chartexample.R
import info.appdev.chartexample.custom.MyMarkerView

class BarChartFrag : SimpleFragment(), OnChartGestureListener {
private var chart: BarChart? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val v = inflater.inflate(R.layout.frag_simple_bar, container, false)

// create a new chart object
chart = BarChart(requireActivity())
chart!!.description.isEnabled = false
chart!!.onChartGestureListener = this

val mv = MyMarkerView(activity, R.layout.custom_marker_view)
mv.chartView = chart // For bounds control
chart!!.setMarker(mv)

chart!!.setDrawGridBackground(false)
chart!!.setDrawBarShadow(false)

val tf = Typeface.createFromAsset(requireContext().assets, "OpenSans-Light.ttf")

chart!!.setData(generateBarData(1, 20000f))

val l = chart!!.legend
l.typeface = tf

val leftAxis = chart!!.axisLeft
leftAxis.typeface = tf
leftAxis.setAxisMinimum(0f) // this replaces setStartAtZero(true)

chart!!.axisRight.isEnabled = false

val xAxis = chart!!.xAxis
xAxis.isEnabled = false

// programmatically add the chart
val parent = v.findViewById<FrameLayout>(R.id.parentLayout)
parent.addView(chart)

return v
}

override fun onChartGestureStart(me: MotionEvent?, lastPerformedGesture: ChartGesture?) {
Log.i("Gesture", "START")
}

override fun onChartGestureEnd(me: MotionEvent?, lastPerformedGesture: ChartGesture?) {
Log.i("Gesture", "END")
chart!!.highlightValues(null)
}

override fun onChartLongPressed(me: MotionEvent?) {
Log.i("LongPress", "Chart long pressed.")
}

override fun onChartDoubleTapped(me: MotionEvent?) {
Log.i("DoubleTap", "Chart double-tapped.")
}

override fun onChartSingleTapped(me: MotionEvent?) {
Log.i("SingleTap", "Chart single-tapped.")
}

override fun onChartFling(me1: MotionEvent?, me2: MotionEvent?, velocityX: Float, velocityY: Float) {
Log.i("Fling", "Chart fling. VelocityX: $velocityX, VelocityY: $velocityY")
}

override fun onChartScale(me: MotionEvent?, scaleX: Float, scaleY: Float) {
Log.i("Scale / Zoom", "ScaleX: $scaleX, ScaleY: $scaleY")
}

override fun onChartTranslate(me: MotionEvent?, dX: Float, dY: Float) {
Log.i("Translate / Move", "dX: $dX, dY: $dY")
}

companion object {
fun newInstance(): Fragment {
return BarChartFrag()
}
}
}
Loading
Loading