Refactoring, prepare example for testing highlight

This commit is contained in:
PhilJay 2016-10-02 15:14:09 +02:00
parent 323329d8a6
commit 3398cf4462
4 changed files with 41 additions and 18 deletions

View file

@ -2,7 +2,6 @@
package com.xxmassdeveloper.mpchartexample;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
@ -16,7 +15,6 @@ import android.widget.Toast;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendForm;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.components.YAxis.AxisDependency;
@ -243,6 +241,7 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
}
case R.id.animateX: {
mChart.animateX(3000);
//mChart.highlightValue(9.7f, 1, false);
break;
}
case R.id.animateY: {
@ -287,30 +286,39 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
for (int i = 0; i < count; i++) {
float mult = range / 2f;
float val = (float) (Math.random() * mult) + 50;// + (float)
// ((mult *
// 0.1) / 10);
float val = (float) (Math.random() * mult) + 50;
yVals1.add(new Entry(i, val));
}
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
for (int i = 0; i < count-1; i++) {
float mult = range;
float val = (float) (Math.random() * mult) + 450;// + (float)
// ((mult *
// 0.1) / 10);
float val = (float) (Math.random() * mult) + 450;
yVals2.add(new Entry(i, val));
// if(i == 10) {
// yVals2.add(new Entry(i, val + 50));
// }
}
LineDataSet set1, set2;
ArrayList<Entry> yVals3 = new ArrayList<Entry>();
for (int i = 0; i < count; i++) {
float mult = range;
float val = (float) (Math.random() * mult) + 500;
yVals3.add(new Entry(i, val));
}
LineDataSet set1, set2, set3;
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1);
set3 = (LineDataSet) mChart.getData().getDataSetByIndex(2);
set1.setValues(yVals1);
set2.setValues(yVals2);
set3.setValues(yVals3);
mChart.getData().notifyDataChanged();
mChart.notifyDataSetChanged();
} else {
@ -344,12 +352,19 @@ public class LineChartActivity2 extends DemoBase implements OnSeekBarChangeListe
set2.setHighLightColor(Color.rgb(244, 117, 117));
//set2.setFillFormatter(new MyFillFormatter(900f));
ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();
dataSets.add(set1); // add the datasets
dataSets.add(set2);
set3 = new LineDataSet(yVals3, "DataSet 3");
set3.setAxisDependency(AxisDependency.RIGHT);
set3.setColor(Color.YELLOW);
set3.setCircleColor(Color.WHITE);
set3.setLineWidth(2f);
set3.setCircleRadius(3f);
set3.setFillAlpha(65);
set3.setFillColor(ColorTemplate.colorWithAlpha(Color.YELLOW, 200));
set3.setDrawCircleHole(false);
set3.setHighLightColor(Color.rgb(244, 117, 117));
// create a data object with the datasets
LineData data = new LineData(dataSets);
LineData data = new LineData(set1, set2, set3);
data.setValueTextColor(Color.WHITE);
data.setValueTextSize(9f);

View file

@ -351,11 +351,14 @@ public abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
int m = (high + low) / 2;
T entry = mValues.get(m);
// if we have a match
if (xValue == entry.getX()) {
while (m > 0 && mValues.get(m - 1).getX() == xValue)
m--;
high = mValues.size();
// loop over all "equal" entries
for (; m < high; m++) {
entry = mValues.get(m);
if (entry.getX() == xValue) {

View file

@ -18,8 +18,6 @@ import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;
public class RadarChartRenderer extends LineRadarRenderer {
protected RadarChart mChart;
@ -306,7 +304,7 @@ public class RadarChartRenderer extends LineRadarRenderer {
}
if (set.getHighlightCircleStrokeAlpha() < 255) {
strokeColor = ColorTemplate.getColorWithAlphaComponent(strokeColor, set.getHighlightCircleStrokeAlpha());
strokeColor = ColorTemplate.colorWithAlpha(strokeColor, set.getHighlightCircleStrokeAlpha());
}
drawHighlightCircle(c,

View file

@ -78,7 +78,14 @@ public class ColorTemplate {
return Color.rgb(51, 181, 229);
}
public static int getColorWithAlphaComponent(int color, int alpha) {
/**
* Sets the alpha component of the given color.
*
* @param color
* @param alpha 0 - 255
* @return
*/
public static int colorWithAlpha(int color, int alpha) {
return (color & 0xffffff) | ((alpha & 0xff) << 24);
}