Skip to content
Closed
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 @@ -14,6 +14,7 @@
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.renderer.BarChartRenderer;
import com.github.mikephil.charting.renderer.RoundedBarChartRenderer;

import java.util.Locale;

Expand Down Expand Up @@ -50,8 +51,9 @@ public class BarChart extends BarLineChartBase<BarData> implements BarDataProvid
private float mRoundedBarRadius = 0f;

private boolean mFitBars = false;
private boolean mIsOwnRoundedRendererUsed = false;

public BarChart(Context context) {
public BarChart(Context context) {
super(context);
}

Expand All @@ -63,12 +65,17 @@ public BarChart(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

protected void setRenderer() {
if (isOwnRoundedRendererUsed())
mRenderer = new RoundedBarChartRenderer(this, mAnimator, mViewPortHandler);
else
mRenderer = new BarChartRenderer(this, mAnimator, mViewPortHandler, mDrawRoundedBars, mRoundedBarRadius);
}

@Override
protected void init() {
super.init();

mRenderer = new BarChartRenderer(this, mAnimator, mViewPortHandler, mDrawRoundedBars, mRoundedBarRadius);

setRenderer();
setHighlighter(new BarHighlighter(this));

getXAxis().setSpaceMin(0.5f);
Expand Down Expand Up @@ -298,4 +305,14 @@ public String getAccessibilityDescription() {
"Data ranges from %s to %s.",
entryCount, entries, minVal, maxVal, minRange, maxRange);
}

@Override
public boolean isOwnRoundedRendererUsed() {
return mIsOwnRoundedRendererUsed;
}

@Override
public void setOwnRoundedRendererUsed(boolean b) {
mIsOwnRoundedRendererUsed = b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Com

protected DrawOrder[] mDrawOrder;

@Override
public boolean isOwnRoundedRendererUsed() {
return false;
}

@Override
public void setOwnRoundedRendererUsed(boolean b) {
Log.e(LOG_TAG, "CombinedChart does not support rounded bars.");
}

/**
* enum that allows to specify the order in which the different data objects
* for the combined-chart are drawn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.github.mikephil.charting.highlight.HorizontalBarHighlighter;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.renderer.HorizontalBarChartRenderer;
import com.github.mikephil.charting.renderer.RoundedHorizontalBarChartRenderer;
import com.github.mikephil.charting.renderer.XAxisRendererHorizontalBarChart;
import com.github.mikephil.charting.renderer.YAxisRendererHorizontalBarChart;
import com.github.mikephil.charting.utils.HorizontalViewPortHandler;
Expand Down Expand Up @@ -40,6 +41,14 @@ public HorizontalBarChart(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
protected void setRenderer() {
if (isOwnRoundedRendererUsed())
mRenderer = new RoundedHorizontalBarChartRenderer(this, mAnimator, mViewPortHandler);
else
mRenderer = new HorizontalBarChartRenderer(this, mAnimator, mViewPortHandler);
}

@Override
protected void init() {

Expand All @@ -50,7 +59,6 @@ protected void init() {
mLeftAxisTransformer = new TransformerHorizontalBarChart(mViewPortHandler);
mRightAxisTransformer = new TransformerHorizontalBarChart(mViewPortHandler);

mRenderer = new HorizontalBarChartRenderer(this, mAnimator, mViewPortHandler);
setHighlighter(new HorizontalBarHighlighter(this));

mAxisRendererLeft = new YAxisRendererHorizontalBarChart(mViewPortHandler, mAxisLeft, mLeftAxisTransformer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ interface BarDataProvider : BarLineScatterCandleBubbleDataProvider {
var isDrawBarShadowEnabled: Boolean
var isDrawValueAboveBarEnabled: Boolean
var isHighlightFullBarEnabled: Boolean
var isOwnRoundedRendererUsed : Boolean
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
<activity android:name="info.appdev.chartexample.LineChartDualAxisActivity" />
<activity android:name="info.appdev.chartexample.LineChartTimeActivity" />
<activity android:name="info.appdev.chartexample.BarChartActivity" />
<activity android:name="info.appdev.chartexample.BarRoundedChartActivity" />
<activity android:name="info.appdev.chartexample.HorizontalBarChartActivity" />
<activity android:name="info.appdev.chartexample.HorizontalBarRoundedChartActivity" />
<activity android:name="info.appdev.chartexample.compose.HorizontalBarComposeActivity" />
<activity android:name="info.appdev.chartexample.HorizontalBarNegativeChartActivity" />
<activity android:name="info.appdev.chartexample.PieChartActivity" />
Expand All @@ -38,7 +40,7 @@
<activity android:name="info.appdev.chartexample.ListViewBarChartActivity" />
<activity android:name="info.appdev.chartexample.ListViewMultiChartActivity" />
<activity android:name="info.appdev.chartexample.StackedBarActivity" />
<activity android:name="AnotherBarActivity" />
<activity android:name=".AnotherBarActivity" />
<activity android:name="info.appdev.chartexample.InvertedLineChartActivity" />
<activity android:name="info.appdev.chartexample.CandleStickChartActivity" />
<activity android:name="info.appdev.chartexample.CubicLineChartActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import info.appdev.chartexample.formatter.MyAxisValueFormatter
import info.appdev.chartexample.notimportant.DemoBase
import timber.log.Timber

class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {
private var chart: BarChart? = null
open class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {
var chart: BarChart? = null
private var seekBarX: SeekBar? = null
private var seekBarY: SeekBar? = null
private var tvX: TextView? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package info.appdev.chartexample

import android.os.Bundle

class BarRoundedChartActivity : BarChartActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
chart!!.isOwnRoundedRendererUsed = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import androidx.core.net.toUri
import info.appdev.chartexample.databinding.ActivityHorizontalbarchartBinding
import timber.log.Timber

class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {
open class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {

private lateinit var binding: ActivityHorizontalbarchartBinding
lateinit var binding: ActivityHorizontalbarchartBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package info.appdev.chartexample

import android.os.Bundle

class HorizontalBarRoundedChartActivity : HorizontalBarChartActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding.chart1.isOwnRoundedRendererUsed = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import info.appdev.chartexample.BarChartActivity
import info.appdev.chartexample.BarChartActivityMultiDataset
import info.appdev.chartexample.BarChartActivitySinus
import info.appdev.chartexample.BarChartPositiveNegative
import info.appdev.chartexample.BarRoundedChartActivity
import info.appdev.chartexample.BubbleChartActivity
import info.appdev.chartexample.CandleStickChartActivity
import info.appdev.chartexample.CombinedChartActivity
Expand All @@ -56,6 +57,7 @@ import info.appdev.chartexample.DynamicalAddingActivity
import info.appdev.chartexample.FilledLineActivity
import info.appdev.chartexample.HalfPieChartActivity
import info.appdev.chartexample.HorizontalBarChartActivity
import info.appdev.chartexample.HorizontalBarRoundedChartActivity
import info.appdev.chartexample.InvertedLineChartActivity
import info.appdev.chartexample.LineChartActivity
import info.appdev.chartexample.LineChartActivityColored
Expand Down Expand Up @@ -166,9 +168,11 @@ class MainActivity : ComponentActivity() {

add(ContentItem("Bar Charts"))
add(ContentItem("Basic", "Simple bar chart.", BarChartActivity::class.java))
add(ContentItem("Basic", "Simple rounded bar chart.", BarRoundedChartActivity::class.java))
add(ContentItem("Basic 2", "Variation of the simple bar chart.", AnotherBarActivity::class.java))
add(ContentItem("Multiple", "Show multiple data sets.", BarChartActivityMultiDataset::class.java))
add(ContentItem("Horizontal", "Render bar chart horizontally.", HorizontalBarChartActivity::class.java))
add(ContentItem("Horizontal", "Render bar rounded chart horizontally.", HorizontalBarRoundedChartActivity::class.java))
add(ContentItem("Stacked", "Stacked bar chart.", StackedBarActivity::class.java))
add(ContentItem("Negative", "Positive and negative values with unique colors.", BarChartPositiveNegative::class.java))
//objects.add(ContentItem("Negative Horizontal", "demonstrates how to create a HorizontalBarChart with positive and negative values."))
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading