Skip to content

Commit

Permalink
Minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Oct 16, 2014
1 parent bb6a556 commit e12e521
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.github.mikephil.charting.utils.Legend;
import com.github.mikephil.charting.utils.Legend.LegendForm;
import com.github.mikephil.charting.utils.LimitLine.LimitLabelPosition;
import com.github.mikephil.charting.utils.Highlight;
import com.github.mikephil.charting.utils.LimitLine;
import com.github.mikephil.charting.utils.XLabels;
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
Expand Down Expand Up @@ -60,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {
mChart = (LineChart) findViewById(R.id.chart1);
mChart.setOnChartGestureListener(this);
mChart.setOnChartValueSelectedListener(this);

mChart.setUnit(" $");
mChart.setDrawUnitsInChart(true);

Expand All @@ -72,7 +73,7 @@ protected void onCreate(Bundle savedInstanceState) {

mChart.setDrawBorder(true);
mChart.setBorderPositions(new BorderPosition[] {
BorderPosition.BOTTOM
BorderPosition.BOTTOM
});

// no description text
Expand Down Expand Up @@ -119,12 +120,12 @@ protected void onCreate(Bundle savedInstanceState) {
// enable/disable highlight indicators (the lines that indicate the
// highlighted Entry)
mChart.setHighlightIndicatorEnabled(false);

// add data
setData(45, 100);

mChart.animateX(2500);

// // restrain the maximum scale-out factor
// mChart.setScaleMinima(3f, 3f);
//
Expand All @@ -138,8 +139,8 @@ protected void onCreate(Bundle savedInstanceState) {
// l.setPosition(LegendPosition.LEFT_OF_CHART);
l.setForm(LegendForm.LINE);

// // dont forget to refresh the drawing
// mChart.invalidate();
// // dont forget to refresh the drawing
// mChart.invalidate();
}

@Override
Expand Down Expand Up @@ -260,15 +261,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
mChart.disableFiltering();
}
mChart.invalidate();

//
// for(int i = 0; i < 10; i++) {
// mChart.addEntry(new Entry((float) (Math.random() * 100), i+2), 0);
// mChart.invalidate();
// }
//
// Toast.makeText(getApplicationContext(), "valcount: " + mChart.getDataOriginal().getYValCount() + ", valsum: " + mChart.getDataOriginal().getYValueSum(), Toast.LENGTH_SHORT).show();
//

//
// for(int i = 0; i < 10; i++) {
// mChart.addEntry(new Entry((float) (Math.random() * 100),
// i+2), 0);
// mChart.invalidate();
// }
//
// Toast.makeText(getApplicationContext(), "valcount: " +
// mChart.getDataOriginal().getYValCount() + ", valsum: " +
// mChart.getDataOriginal().getYValueSum(),
// Toast.LENGTH_SHORT).show();
//
break;
}
case R.id.actionSave: {
Expand Down Expand Up @@ -326,11 +331,11 @@ private void setData(int count, float range) {
// 0.1) / 10);
yVals.add(new Entry(val, i));
}

// create a dataset and give it a type
LineDataSet set1 = new LineDataSet(yVals, "DataSet 1");
// set1.setFillAlpha(110);
// set1.setFillColor(Color.RED);
// set1.setFillAlpha(110);
// set1.setFillColor(Color.RED);

// set the line to be drawn like this "- - - - - -"
set1.enableDashedLine(10f, 5f, 0f);
Expand All @@ -340,26 +345,27 @@ private void setData(int count, float range) {
set1.setCircleSize(4f);
set1.setFillAlpha(65);
set1.setFillColor(Color.BLACK);
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
// set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(),
// Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));

ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
dataSets.add(set1); // add the datasets

// create a data object with the datasets
LineData data = new LineData(xVals, dataSets);

LimitLine ll1 = new LimitLine(130f);
ll1.setLineWidth(4f);
ll1.enableDashedLine(10f, 10f, 0f);
ll1.setDrawValue(true);
ll1.setLabelPosition(LimitLabelPosition.RIGHT);

LimitLine ll2 = new LimitLine(-30f);
ll2.setLineWidth(4f);
ll2.enableDashedLine(10f, 10f, 0f);
ll2.setDrawValue(true);
ll2.setLabelPosition(LimitLabelPosition.RIGHT);

data.addLimitLine(ll1);
data.addLimitLine(ll2);

Expand All @@ -374,19 +380,19 @@ public void onChartLongPressed(MotionEvent me) {

@Override
public void onChartDoubleTapped(MotionEvent me) {
Log.i("DoubleTap", "Chart double-tapped.");
Log.i("DoubleTap", "Chart double-tapped.");
}

@Override
public void onChartSingleTapped(MotionEvent me) {
Log.i("SingleTap", "Chart single-tapped.");
}

@Override
public void onValueSelected(Entry e, int dataSetIndex) {
Log.i("Entry selected", e.toString());
}

@Override
public void onNothingSelected() {
Log.i("Nothing selected", "Nothing selected.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@
package com.xxmassdeveloper.mpchartexample;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.MarkerView;
import com.github.mikephil.charting.utils.Utils;

public class MyMarkerView extends MarkerView implements OnClickListener {
public class MyMarkerView extends MarkerView {

private TextView tvContent;

public MyMarkerView(Context context, int layoutResource) {
super(context, layoutResource);

tvContent = (TextView) findViewById(R.id.tvContent);
setOnClickListener(this);
}

// callbacks everytime the MarkerView is redrawn, can be used to update the
Expand All @@ -38,9 +34,4 @@ public void refreshContent(Entry e, int dataSetIndex) {
tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));
}
}

@Override
public void onClick(View v) {
Toast.makeText(getContext(), "Marker clicked!", Toast.LENGTH_SHORT).show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewParent;

import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarLineScatterCandleData;
Expand Down
28 changes: 25 additions & 3 deletions MPChartLib/src/com/github/mikephil/charting/charts/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,10 @@ protected void drawLegend() {
break;
case PIECHART_CENTER:

posX = getWidth() / 2f
- (mLegend.getMaximumEntryLength(mLegendLabelPaint) + mLegend.getXEntrySpace())
posX = getWidth()
/ 2f
- (mLegend.getMaximumEntryLength(mLegendLabelPaint) + mLegend
.getXEntrySpace())
/ 2f;
posY = getHeight() / 2f - mLegend.getFullHeight(mLegendLabelPaint) / 2f;

Expand Down Expand Up @@ -1065,6 +1067,26 @@ public void highlightValues(Highlight[] highs) {
invalidate();
}

/**
* Highlights the value at the given x-index in the given DataSet. Provide
* -1 as the x-index to undo all highlighting.
*
* @param xIndex
* @param dataSetIndex
*/
public void highlightValue(int xIndex, int dataSetIndex) {

if (xIndex < 0 || dataSetIndex < 0 || xIndex >= mOriginalData.getXValCount()
|| dataSetIndex >= mOriginalData.getDataSetCount()) {

highlightValues(null);
} else {
highlightValues(new Highlight[] {
new Highlight(xIndex, dataSetIndex)
});
}
}

/**
* Highlights the value selected by touch gesture. Unlike
* highlightValues(...), this generates a callback to the
Expand Down Expand Up @@ -1713,7 +1735,7 @@ public Legend getLegend() {
public RectF getContentRect() {
return mContentRect;
}

/**
* disables intercept touchevents
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.OnChartGestureListener;
import com.github.mikephil.charting.utils.Highlight;
import com.github.mikephil.charting.utils.MarkerView;

/**
* TouchListener for Bar-, Line-, Scatter- and CandleStickChart with handles all
Expand Down

0 comments on commit e12e521

Please sign in to comment.