Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/catching up to ios #4787

Merged
merged 27 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
95027fa
Safe guards
danielgindi Jan 22, 2020
6ebf3fa
Added highlightColor parameter for pie charts
danielgindi Jan 22, 2020
1987d7e
Consider axis dependency in Combined chart
danielgindi Jan 22, 2020
634a690
Added an implementation of Douglas Peucker with resultCount input
danielgindi Jan 22, 2020
a4ca1f3
Fixed axis label disappearing when zooming in
danielgindi Jan 22, 2020
2e725e4
Make min/max axis labels configurable
danielgindi Jan 22, 2020
3f54750
Avoid race condition for interval/intervalMagnitude
danielgindi Jan 22, 2020
912427e
Custom text alignment for no-data
danielgindi Jan 22, 2020
4549ae1
Select correct axis for legend distance calculation in horz bar chart
danielgindi Jan 22, 2020
bafb0fb
Use correct color index for bubble chart
danielgindi Jan 22, 2020
ea816e8
Added dataIndex param for highlightValue (combined charts)
danielgindi Jan 22, 2020
34c3cea
Reset min/max when clearing ChartDataSet
danielgindi Jan 22, 2020
8df9eda
Call notifyDataChanged for an opportunity for subclasses
danielgindi Jan 22, 2020
4ce14e6
Add a warning message if pie chart has more than one data set
danielgindi Jan 22, 2020
58545bb
Add option to disable clipping data to contentRect
danielgindi Jan 22, 2020
7752efe
Support for labelXOffset for YAxis label
danielgindi Jan 22, 2020
ae59e7a
This is for the inline bubble selection
danielgindi Jan 22, 2020
c97c8d2
Fixed index out of bounds issue when using stacked bar chart
danielgindi Jan 22, 2020
13aee59
Improve min/max calculation
danielgindi Jan 22, 2020
fcc5af7
Call onChartScale listener after double-tap-zoom
danielgindi Jan 22, 2020
e02e9be
Multiple colors for valueline
danielgindi Jan 22, 2020
14456f4
Renamed values -> entries for consistency
danielgindi Jan 22, 2020
45240c3
Improved negative offset for horz bar chart
danielgindi Jan 22, 2020
34fefd2
maxHeight didn't account for the last label
danielgindi Jan 23, 2020
0668d30
Fixed a bug where a pie slice without highlight enabled is hidden
danielgindi Jan 23, 2020
1de836a
Remove unexpected dash line during linear animation
danielgindi Jan 23, 2020
5e4a32e
Corrected check for line in vertical bounds
danielgindi Jan 23, 2020
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
@@ -0,0 +1,288 @@

package com.xxmassdeveloper.mpchartexample;

import android.annotation.SuppressLint;
import android.graphics.RectF;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import com.github.mikephil.charting.charts.HorizontalBarChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
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.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.MPPointF;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;

import java.util.ArrayList;
import java.util.List;

public class HorizontalBarNegativeChartActivity extends DemoBase implements OnSeekBarChangeListener,
OnChartValueSelectedListener {

protected HorizontalBarChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private TextView tvX, tvY;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_horizontalbarchart);

tvX = findViewById(R.id.tvXMax);
tvY = (TextView) findViewById(R.id.tvYMax);

mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

mChart = (HorizontalBarChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
// mChart.setHighlightEnabled(false);

mChart.setDrawBarShadow(false);

mChart.setDrawValueAboveBar(true);

mChart.getDescription().setEnabled(false);

// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);

// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);

// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);

mChart.setDrawGridBackground(false);

XAxis xl = mChart.getXAxis();
xl.setPosition(XAxisPosition.BOTTOM);
xl.setTypeface(mTfLight);
xl.setDrawAxisLine(true);
xl.setDrawGridLines(false);
xl.setGranularity(10f);

YAxis yl = mChart.getAxisLeft();
yl.setTypeface(mTfLight);
yl.setDrawAxisLine(true);
yl.setDrawGridLines(true);
yl.setDrawZeroLine(true); // draw a zero line
// yl.setInverted(true);

YAxis yr = mChart.getAxisRight();
yr.setTypeface(mTfLight);
yr.setDrawAxisLine(true);
yr.setDrawGridLines(false);
// yr.setInverted(true);

setData(12, 50);
mChart.setFitBars(true);
mChart.animateY(2500);

// setting data
mSeekBarY.setProgress(50);
mSeekBarX.setProgress(12);

mSeekBarY.setOnSeekBarChangeListener(this);
mSeekBarX.setOnSeekBarChangeListener(this);

Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setFormSize(8f);
l.setXEntrySpace(4f);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.bar, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case R.id.actionToggleValues: {
List<IBarDataSet> sets = mChart.getData()
.getDataSets();

for (IBarDataSet iSet : sets) {

IBarDataSet set = (BarDataSet) iSet;
set.setDrawValues(!set.isDrawValuesEnabled());
}

mChart.invalidate();
break;
}
case R.id.actionToggleIcons: {
List<IBarDataSet> sets = mChart.getData()
.getDataSets();

for (IBarDataSet iSet : sets) {

IBarDataSet set = (BarDataSet) iSet;
set.setDrawIcons(!set.isDrawIconsEnabled());
}

mChart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
}
break;
}
case R.id.actionTogglePinch: {
if (mChart.isPinchZoomEnabled())
mChart.setPinchZoom(false);
else
mChart.setPinchZoom(true);

mChart.invalidate();
break;
}
case R.id.actionToggleAutoScaleMinMax: {
mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled());
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);

mChart.invalidate();
break;
}
case R.id.animateX: {
mChart.animateX(3000);
break;
}
case R.id.animateY: {
mChart.animateY(3000);
break;
}
case R.id.animateXY: {

mChart.animateXY(3000, 3000);
break;
}
case R.id.actionSave: {
if (mChart.saveToGallery("title" + System.currentTimeMillis(), 50)) {
Toast.makeText(getApplicationContext(), "Saving SUCCESSFUL!",
Toast.LENGTH_SHORT).show();
} else
Toast.makeText(getApplicationContext(), "Saving FAILED!", Toast.LENGTH_SHORT)
.show();
break;
}
}
return true;
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

tvX.setText("" + (mSeekBarX.getProgress() + 1));
tvY.setText("" + (mSeekBarY.getProgress()));

setData(mSeekBarX.getProgress() + 1, mSeekBarY.getProgress());
mChart.setFitBars(true);
mChart.invalidate();
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}

private void setData(int count, float range) {

float barWidth = 9f;
float spaceForBar = 10f;
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();

for (int i = 0; i < count; i++) {
float val = (float) (Math.random() * range - range / 2);
yVals1.add(new BarEntry(i * spaceForBar, val,
getResources().getDrawable(R.drawable.star)));
}

BarDataSet set1;

if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set1.setValues(yVals1);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(yVals1, "DataSet 1");

set1.setDrawIcons(false);

ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);

BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(mTfLight);
data.setBarWidth(barWidth);
mChart.setData(data);
}
}

protected RectF mOnValueSelectedRectF = new RectF();
@SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, Highlight h) {

if (e == null)
return;

RectF bounds = mOnValueSelectedRectF;
mChart.getBarBounds((BarEntry) e, bounds);

MPPointF position = mChart.getPosition(e, mChart.getData().getDataSetByIndex(h.getDataSetIndex())
.getAxisDependency());

Log.i("bounds", bounds.toString());
Log.i("position", position.toString());

MPPointF.recycleInstance(position);
}

@Override
public void onNothingSelected() {
};
}
1 change: 1 addition & 0 deletions MPChartExample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<activity android:name="LineChartTime" />
<activity android:name="BarChartActivity" />
<activity android:name="HorizontalBarChartActivity" />
<activity android:name="HorizontalBarNegativeChartActivity" />
<activity android:name="PieChartActivity" />
<activity android:name="PiePolylineChartActivity" />
<activity android:name="MultiLineChartActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ private void setData(int count, float range) {
dataSet.setValueLinePart1OffsetPercentage(80.f);
dataSet.setValueLinePart1Length(0.2f);
dataSet.setValueLinePart2Length(0.4f);
//dataSet.setUsingSliceColorAsValueLineColor(true);

//dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
Expand Down
Loading