Work on highlighting
This commit is contained in:
parent
858600dcd2
commit
c28b41b05e
7 changed files with 42 additions and 16 deletions
|
@ -36,6 +36,7 @@ import com.github.mikephil.charting.utils.ColorTemplate;
|
|||
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CombinedChartActivity extends DemoBase {
|
||||
|
||||
|
@ -137,7 +138,9 @@ public class CombinedChartActivity extends DemoBase {
|
|||
|
||||
for (int index = 0; index < itemcount; index++) {
|
||||
entries1.add(new BarEntry(0, getRandom(25, 25)));
|
||||
entries2.add(new BarEntry(0, getRandom(25, 25)));
|
||||
|
||||
// stacked
|
||||
entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)}));
|
||||
}
|
||||
|
||||
BarDataSet set1 = new BarDataSet(entries1, "Bar 1");
|
||||
|
@ -147,7 +150,7 @@ public class CombinedChartActivity extends DemoBase {
|
|||
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
|
||||
|
||||
BarDataSet set2 = new BarDataSet(entries2, "Bar 2");
|
||||
set2.setColor(Color.rgb(61, 165, 255));
|
||||
set2.setColors(new int[]{Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)});
|
||||
set2.setValueTextColor(Color.rgb(61, 165, 255));
|
||||
set2.setValueTextSize(10f);
|
||||
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
|
||||
|
|
|
@ -187,7 +187,6 @@ public class BarChart extends BarLineChartBase<BarData> implements BarDataProvid
|
|||
return mData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds half of the bar width to each side of the x-axis range in order to allow the bars of the barchart to be
|
||||
* fully displayed.
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.github.mikephil.charting.formatter.DefaultValueFormatter;
|
|||
import com.github.mikephil.charting.formatter.ValueFormatter;
|
||||
import com.github.mikephil.charting.highlight.ChartHighlighter;
|
||||
import com.github.mikephil.charting.highlight.Highlight;
|
||||
import com.github.mikephil.charting.highlight.Highlighter;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.ChartInterface;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
|
||||
import com.github.mikephil.charting.listener.ChartTouchListener;
|
||||
|
@ -162,7 +163,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
*/
|
||||
protected DataRenderer mRenderer;
|
||||
|
||||
protected ChartHighlighter mHighlighter;
|
||||
protected Highlighter mHighlighter;
|
||||
|
||||
/**
|
||||
* object that manages the bounds and drawing constraints of the chart
|
||||
|
@ -1446,7 +1447,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
mRenderer = renderer;
|
||||
}
|
||||
|
||||
public ChartHighlighter getHighlighter() {
|
||||
public Highlighter getHighlighter() {
|
||||
return mHighlighter;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Lin
|
|||
protected void init() {
|
||||
super.init();
|
||||
|
||||
setHighlighter(new CombinedHighlighter(this));
|
||||
setHighlighter(new CombinedHighlighter(this, this));
|
||||
|
||||
// Old default behaviour
|
||||
setHighlightFullBarEnabled(true);
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.github.mikephil.charting.utils.SelectionDetail;
|
|||
/**
|
||||
* Created by Philipp Jahoda on 21/07/15.
|
||||
*/
|
||||
public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider> {
|
||||
public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider> implements Highlighter {
|
||||
|
||||
/**
|
||||
* instance of the data-provider
|
||||
|
@ -25,13 +25,7 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
|
|||
this.mChart = chart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Highlight object corresponding to the given x- and y- touch positions in pixels.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Highlight getHighlight(float x, float y) {
|
||||
|
||||
float xVal = (float) getValsForTouch(x, y).x;
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.github.mikephil.charting.highlight;
|
|||
import com.github.mikephil.charting.data.ChartData;
|
||||
import com.github.mikephil.charting.data.CombinedData;
|
||||
import com.github.mikephil.charting.data.DataSet;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
|
||||
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
|
||||
import com.github.mikephil.charting.interfaces.dataprovider.BarLineScatterCandleBubbleDataProvider;
|
||||
import com.github.mikephil.charting.utils.SelectionDetail;
|
||||
|
@ -13,10 +14,22 @@ import java.util.List;
|
|||
/**
|
||||
* Created by Philipp Jahoda on 12/09/15.
|
||||
*/
|
||||
public class CombinedHighlighter extends ChartHighlighter<BarLineScatterCandleBubbleDataProvider> {
|
||||
public class CombinedHighlighter extends ChartHighlighter<BarLineScatterCandleBubbleDataProvider> implements Highlighter {
|
||||
|
||||
public CombinedHighlighter(BarLineScatterCandleBubbleDataProvider chart) {
|
||||
protected BarHighlighter barHighlighter;
|
||||
|
||||
public CombinedHighlighter(BarLineScatterCandleBubbleDataProvider chart, BarDataProvider barChart) {
|
||||
super(chart);
|
||||
barHighlighter = new BarHighlighter(barChart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Highlight getHighlight(float x, float y) {
|
||||
|
||||
Highlight h1 = super.getHighlight(x, y);
|
||||
Highlight h2 = barHighlighter.getHighlight(x, y);
|
||||
|
||||
return h1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.github.mikephil.charting.highlight;
|
||||
|
||||
/**
|
||||
* Created by philipp on 10/06/16.
|
||||
*/
|
||||
public interface Highlighter {
|
||||
|
||||
/**
|
||||
* Returns a Highlight object corresponding to the given x- and y- touch positions in pixels.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @return
|
||||
*/
|
||||
Highlight getHighlight(float x, float y);
|
||||
}
|
Loading…
Add table
Reference in a new issue