com.github.mikephil.charting.data.BarEntry Java Examples

The following examples show how to use com.github.mikephil.charting.data.BarEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StackedBarsMarkerView.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void refreshContent(Entry e, Highlight highlight) {

    if (e instanceof BarEntry) {

        BarEntry be = (BarEntry) e;

        if(be.getYVals() != null) {

            // draw the stack value
            tvContent.setText(Utils.formatNumber(be.getYVals()[highlight.getStackIndex()], 0, true));
        } else {
            tvContent.setText(Utils.formatNumber(be.getY(), 0, true));
        }
    } else {

        tvContent.setText(Utils.formatNumber(e.getY(), 0, true));
    }

    super.refreshContent(e, highlight);
}
 
Example #2
Source File: ProductDetailActivity.java    From FaceT with Mozilla Public License 2.0 6 votes vote down vote up
public BarData getBarData() {

        ArrayList<BarEntry> entries = new ArrayList<>();
        float overall_people = 100f;

        Log.d(TAG + "barData", barRatingCount[3] + "");
        entries.add(new BarEntry(4, barRatingCount[4]));
        entries.add(new BarEntry(3, barRatingCount[3]));
        entries.add(new BarEntry(2, barRatingCount[2]));
        entries.add(new BarEntry(1, barRatingCount[1]));
        entries.add(new BarEntry(0, barRatingCount[0]));

        BarDataSet dataset = new BarDataSet(entries, "");
        dataset.setColors(CUSTOM_COLOR);
        dataset.setDrawValues(false);

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

        BarData data = new BarData(dataSets);
//        data.setValueTextSize(10f);
//        data.setValueTypeface(fontType);
        data.setBarWidth(1f);

        return data;
    }
 
Example #3
Source File: BarChart.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be
 * found in the charts data.
 * 
 * @param e
 * @return
 */
public RectF getBarBounds(BarEntry e) {

	IBarDataSet set = mData.getDataSetForEntry(e);

	if (set == null)
		return null;

	float barspace = set.getBarSpace();
	float y = e.getVal();
	float x = e.getXIndex();

	float barWidth = 0.5f;

	float spaceHalf = barspace / 2f;
	float left = x - barWidth + spaceHalf;
	float right = x + barWidth - spaceHalf;
	float top = y >= 0 ? y : 0;
	float bottom = y <= 0 ? y : 0;

	RectF bounds = new RectF(left, top, right, bottom);

	getTransformer(set.getAxisDependency()).rectValueToPixel(bounds);

	return bounds;
}
 
Example #4
Source File: BarChartActivitySinus.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData(int count) {

        ArrayList<String> xVals = new ArrayList<String>();
        
        ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
        
        for (int i = 0; i < count; i++) {
            xVals.add(i+"");
            entries.add(mSinusData.get(i));
        }
        
        BarDataSet set = new BarDataSet(entries, "Sinus Function");
        set.setBarSpacePercent(40f);
        set.setColor(Color.rgb(240, 120, 124));

        BarData data = new BarData(xVals, set);
        data.setValueTextSize(10f);
        data.setValueTypeface(mTf);
        data.setDrawValues(false);

        mChart.setData(data);
    }
 
Example #5
Source File: HorizontalBarChart.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;
    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        outputRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float top = x - barWidth / 2f;
    float bottom = x + barWidth / 2f;
    float left = y >= 0 ? y : 0;
    float right = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(bounds);

}
 
Example #6
Source File: ListViewBarChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 * 
 * @return
 */
private BarData generateData(int cnt) {

    ArrayList<BarEntry> entries = new ArrayList<BarEntry>();

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry((int) (Math.random() * 70) + 30, i));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);    
    d.setBarSpacePercent(20f);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setBarShadowColor(Color.rgb(203, 203, 203));
    
    ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
    sets.add(d);
    
    BarData cd = new BarData(getMonths(), sets);
    return cd;
}
 
Example #7
Source File: BarChart.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
/**
 * The passed outputRect will be assigned the values of the bounding box of the specified Entry in the specified DataSet.
 * The rect will be assigned Float.MIN_VALUE in all locations if the Entry could not be found in the charts data.
 *
 * @param e
 * @return
 */
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;

    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        bounds.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float left = x - barWidth / 2f;
    float right = x + barWidth / 2f;
    float top = y >= 0 ? y : 0;
    float bottom = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(outputRect);
}
 
Example #8
Source File: KLineDataManage.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 初始化自己计算MACD
 */
public void initMACD() {
    MACDEntity macdEntity = new MACDEntity(getKLineDatas(), SHORT, LONG, M);

    macdData = new ArrayList<>();
    deaData = new ArrayList<>();
    difData = new ArrayList<>();
    for (int i = 0; i < macdEntity.getMACD().size(); i++) {
        macdData.add(new BarEntry(i + offSet, macdEntity.getMACD().get(i), macdEntity.getMACD().get(i)));
        deaData.add(new Entry(i + offSet, macdEntity.getDEA().get(i)));
        difData.add(new Entry(i + offSet, macdEntity.getDIF().get(i)));
    }
    barDataMACD = setABar(macdData);
    lineDataMACD.add(setALine(ColorType.blue, deaData));
    lineDataMACD.add(setALine(ColorType.yellow, difData));
}
 
Example #9
Source File: AvgAnalysisActivity.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
private List<BarEntry> generateEntry(List<TicketOpenData> list, int codeLength) {
    float[] valuesCount = new float[codeLength];
    for (int j = 0; j < list.size(); j++) {
        Pair<String[], String[]> sPair = translateCodeToList(list.get(j).openCode);
        String[] values = ArrayUtil.concat(sPair.first, sPair.second);
        for (int k = 0; k < codeLength; k++) {
            try {
                valuesCount[k] += Float.valueOf(values[k]);//非数字直接抛异常
            } catch (Exception e) {
                e.printStackTrace();
                valuesCount[k] += 0;
            }
        }
    }
    List<BarEntry> barEntries = new ArrayList<>();
    float count = 0;
    for (int i = 0; i < codeLength - 1; i++) {
        count += valuesCount[i] / list.size();
        barEntries.add(new BarEntry(i, valuesCount[i] / list.size()));
    }
    barEntries.add(new BarEntry(codeLength - 1, count));
    return barEntries;
}
 
Example #10
Source File: OneDayChart.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * 动态增加一个点数据
 * @param timeDatamodel
 * @param length
 */
public void dynamicsAddOne(TimeDataModel timeDatamodel, int length) {
    int index = length - 1;
    LineData lineData = lineChart.getData();
    ILineDataSet d1 = lineData.getDataSetByIndex(0);
    d1.addEntry(new Entry(index, (float) timeDatamodel.getNowPrice()));
    ILineDataSet d2 = lineData.getDataSetByIndex(1);
    d2.addEntry(new Entry(index, (float) timeDatamodel.getAveragePrice()));

    BarData barData = barChart.getData();
    IBarDataSet barDataSet = barData.getDataSetByIndex(0);
    float color = timeDatamodel.getNowPrice() == d1.getEntryForIndex(index - 1).getY() ? 0f : timeDatamodel.getNowPrice() > d1.getEntryForIndex(index - 1).getY() ? 1f : -1f;
    barDataSet.addEntry(new BarEntry(index, timeDatamodel.getVolume(),color));
    lineData.notifyDataChanged();
    lineChart.notifyDataSetChanged();
    barData.notifyDataChanged();
    barChart.notifyDataSetChanged();
    lineChart.setVisibleXRange(maxCount, maxCount);
    barChart.setVisibleXRange(maxCount, maxCount);
    //动态添加或移除数据后, 调用invalidate()刷新图表之前 必须调用 notifyDataSetChanged() .
    lineChart.moveViewToX(index);
    barChart.moveViewToX(index);
}
 
Example #11
Source File: HorizontalBarChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public void onValueSelected(Entry e, Highlight h) {

    if (e == null)
        return;

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

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

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

    MPPointF.recycleInstance(position);
}
 
Example #12
Source File: BarChart.java    From Notification-Analyser with MIT License 6 votes vote down vote up
/**
 * Returns the bounding box of the specified Entry in the specified DataSet.
 * Returns null if the Entry could not be found in the charts data.
 * 
 * @param e
 * @param dataSetIndex
 * @return
 */
public RectF getBarBounds(BarEntry e) {

    BarDataSet set = mOriginalData.getDataSetForEntry(e);

    if (set == null)
        return null;

    float barspace = set.getBarSpace();
    float y = e.getVal();
    float x = e.getXIndex();

    float spaceHalf = barspace / 2f;
    float left = x + spaceHalf;
    float right = x + 1f - spaceHalf;
    float top = y >= 0 ? y : 0;
    float bottom = y <= 0 ? y : 0;

    RectF bounds = new RectF(left, top, right, bottom);

    transformRect(bounds);

    return bounds;
}
 
Example #13
Source File: HorizontalBarChart.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void getBarBounds(BarEntry e, RectF outputRect) {

    RectF bounds = outputRect;
    IBarDataSet set = mData.getDataSetForEntry(e);

    if (set == null) {
        outputRect.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
        return;
    }

    float y = e.getY();
    float x = e.getX();

    float barWidth = mData.getBarWidth();

    float top = x - barWidth / 2f;
    float bottom = x + barWidth / 2f;
    float left = y >= 0 ? y : 0;
    float right = y <= 0 ? y : 0;

    bounds.set(left, top, right, bottom);

    getTransformer(set.getAxisDependency()).rectValueToPixel(bounds);

}
 
Example #14
Source File: StackedValueFormatter.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

    if (!mDrawWholeStack && entry instanceof BarEntry) {

        BarEntry barEntry = (BarEntry) entry;
        float[] vals = barEntry.getYVals();

        if (vals != null) {

            // find out if we are on top of the stack
            if (vals[vals.length - 1] == value) {

                // return the "sum" across all stack values
                return mFormat.format(barEntry.getY()) + mAppendix;
            } else {
                return ""; // return empty
            }
        }
    }

    // return the "proposed" value
    return mFormat.format(value) + mAppendix;
}
 
Example #15
Source File: SimpleFragment.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
protected BarData generateBarData(int dataSets, float range, int count) {

        ArrayList<IBarDataSet> sets = new ArrayList<>();

        for(int i = 0; i < dataSets; i++) {

            ArrayList<BarEntry> entries = new ArrayList<>();

            for(int j = 0; j < count; j++) {
                entries.add(new BarEntry(j, (float) (Math.random() * range) + range / 4));
            }

            BarDataSet ds = new BarDataSet(entries, getLabel(i));
            ds.setColors(ColorTemplate.VORDIPLOM_COLORS);
            sets.add(ds);
        }

        BarData d = new BarData(sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example #16
Source File: StackedValueFormatter.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public String getBarStackedLabel(float value, BarEntry entry) {
    if (!mDrawWholeStack) {

        float[] vals = entry.getYVals();

        if (vals != null) {

            // find out if we are on top of the stack
            if (vals[vals.length - 1] == value) {

                // return the "sum" across all stack values
                return mFormat.format(entry.getY()) + mSuffix;
            } else {
                return ""; // return empty
            }
        }
    }

    // return the "proposed" value
    return mFormat.format(value) + mSuffix;
}
 
Example #17
Source File: ListViewBarChartActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
/**
 * generates a random ChartData object with just one DataSet
 *
 * @return Bar data
 */
private BarData generateData(int cnt) {

    ArrayList<BarEntry> entries = new ArrayList<>();

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry(i, (float) (Math.random() * 70) + 30));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    d.setBarShadowColor(Color.rgb(203, 203, 203));

    ArrayList<IBarDataSet> sets = new ArrayList<>();
    sets.add(d);

    BarData cd = new BarData(sets);
    cd.setBarWidth(0.9f);
    return cd;
}
 
Example #18
Source File: StackedValueFormatter.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {

    if (!mDrawWholeStack && entry instanceof BarEntry) {

        BarEntry barEntry = (BarEntry) entry;
        float[] vals = barEntry.getVals();

        if (vals != null) {

            // find out if we are on top of the stack
            if (vals[vals.length - 1] == value) {

                // return the "sum" across all stack values
                return mFormat.format(barEntry.getVal()) + mAppendix;
            } else {
                return ""; // return empty
            }
        }
    }

    // return the "proposed" value
    return mFormat.format(value) + mAppendix;
}
 
Example #19
Source File: TimeLineView.java    From android-kline with Apache License 2.0 6 votes vote down vote up
private void initChartVolumeData() {
    ArrayList<BarEntry> barEntries = new ArrayList<>();
    ArrayList<BarEntry> paddingEntries = new ArrayList<>();
    for (int i = 0; i < mData.size(); i++) {
        HisData t = mData.get(i);
        barEntries.add(new BarEntry(i, (float) t.getVol(), t));
    }
    int maxCount = MAX_COUNT;
    if (!mData.isEmpty() && mData.size() < maxCount) {
        for (int i = mData.size(); i < maxCount; i++) {
            paddingEntries.add(new BarEntry(i, 0));
        }
    }

    BarData barData = new BarData(setBar(barEntries, NORMAL_LINE), setBar(paddingEntries, INVISIABLE_LINE));
    barData.setBarWidth(0.75f);
    CombinedData combinedData = new CombinedData();
    combinedData.setData(barData);
    mChartVolume.setData(combinedData);

    mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT);

    mChartVolume.notifyDataSetChanged();
    mChartVolume.moveViewToX(combinedData.getEntryCount());

}
 
Example #20
Source File: RealmBarDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 6 votes vote down vote up
@Override
protected void calcMinMax(BarEntry e) {

    if (e != null && !Float.isNaN(e.getY())) {

        if (e.getYVals() == null) {

            if (e.getY() < mYMin)
                mYMin = e.getY();

            if (e.getY() > mYMax)
                mYMax = e.getY();
        } else {

            if (-e.getNegativeSum() < mYMin)
                mYMin = -e.getNegativeSum();

            if (e.getPositiveSum() > mYMax)
                mYMax = e.getPositiveSum();
        }

        calcMinMaxX(e);
    }
}
 
Example #21
Source File: ScrollViewActivity.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private void setData(int count) {

        ArrayList<BarEntry> values = new ArrayList<>();

        for (int i = 0; i < count; i++) {
            float val = (float) (Math.random() * count) + 15;
            values.add(new BarEntry(i, (int) val));
        }

        BarDataSet set = new BarDataSet(values, "Data Set");
        set.setColors(ColorTemplate.VORDIPLOM_COLORS);
        set.setDrawValues(false);

        BarData data = new BarData(set);

        chart.setData(data);
        chart.invalidate();
        chart.animateY(800);
    }
 
Example #22
Source File: StatisticActivity.java    From memorize with MIT License 6 votes vote down vote up
private BarData generateDataBar(int cnt) {

        ArrayList<BarEntry> entries = new ArrayList<>();

        for (int i = 0; i < 12; i++) {
            entries.add(new BarEntry(i, (int) (Math.random() * 70) + 30));
        }

        BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
        d.setColors(ColorTemplate.VORDIPLOM_COLORS);
        d.setHighLightAlpha(255);

        BarData cd = new BarData(d);
        cd.setBarWidth(0.9f);
        return cd;
    }
 
Example #23
Source File: RealmBarDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 6 votes vote down vote up
@Override
public BarEntry buildEntryFromResultObject(T realmObject, float x) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    if (dynamicObject.getFieldType(mYValuesField) == RealmFieldType.LIST) {

        RealmList<DynamicRealmObject> list = dynamicObject.getList(mYValuesField);
        float[] values = new float[list.size()];

        int i = 0;
        for (DynamicRealmObject o : list) {
            values[i] = o.getFloat(mStackValueFieldName);
            i++;
        }

        return new BarEntry(
                mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), values);
    } else {
        float value = dynamicObject.getFloat(mYValuesField);
        return new BarEntry(mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), value);
    }
}
 
Example #24
Source File: MainActivity.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
private void initChart() {
    ArrayList<BarDataSet> dataSets = new ArrayList<>();
    // note that we show save first because that's how we initialize the DB
    for (String frameworkName : chartEntrySets.keySet()) {
        ArrayList<BarEntry> entrySet = chartEntrySets.get(frameworkName);
        BarDataSet dataSet = new BarDataSet(entrySet, frameworkName);
        dataSet.setColor(getFrameworkColor(frameworkName));
        dataSets.add(dataSet);
    }
    // load data and animate it
    ArrayList<String> xAxisLabels = new ArrayList<>();
    xAxisLabels.add("Save (msec)");
    xAxisLabels.add("Load (msec)");
    BarData data = new BarData(xAxisLabels, dataSets);
    chartView.setData(data);
    chartView.setDescription(null); // this takes up too much space, so clear it
    chartView.animateXY(2000, 2000);
    chartView.invalidate();
}
 
Example #25
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 6/1/18
 * author: chenli
 * description: K线图刷新时生成单个数据
 */
private void generateCandleAndLineDataEntry(int left_index, int index) {
    Map<String, KlineEntity.DataEntity> dataEntities = mKlineEntity.getData();
    KlineEntity.DataEntity dataEntity = dataEntities.get(String.valueOf(index));
    if (dataEntity == null) return;
    mCalendar.setTimeInMillis(Long.valueOf(dataEntity.getDatetime()) / 1000000);
    xVals.put(index - mBaseIndex, mSimpleDateFormat.format(mCalendar.getTime()));

    List<Entry> entries = generateMultiDataEntry(index, dataEntity, left_index);
    mTopChartViewBase.getCandleData().getDataSetByIndex(0).addEntryOrdered((CandleEntry) entries.get(0));
    mMiddleChartViewBase.getLineData().getDataSetByIndex(0).addEntryOrdered(entries.get(1));
    mMiddleChartViewBase.getBarData().getDataSetByIndex(0).addEntryOrdered((BarEntry) entries.get(2));
    mBottomChartViewBase.getLineData().getDataSetByIndex(0).addEntryOrdered(entries.get(3));
    mBottomChartViewBase.getLineData().getDataSetByIndex(1).addEntryOrdered(entries.get(4));
    mBottomChartViewBase.getBarData().getDataSetByIndex(0).addEntryOrdered((BarEntry) entries.get(5));

    for (int i = 0; i < mas.size(); i++) {
        int para = mas.get(i);
        if (index >= left_index + para - 1) {
            Entry entry = generateMALineDataEntry(index, para - 1);
            mLineData.getDataSetByIndex(i).addEntryOrdered(entry);
        }
    }
}
 
Example #26
Source File: HorizontalBarChartActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData(int count, float range) {

        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
        ArrayList<String> xVals = new ArrayList<String>();

        for (int i = 0; i < count; i++) {
            xVals.add(mMonths[i % 12]);
            yVals1.add(new BarEntry((float) (Math.random() * range), i));
        }

        BarDataSet set1 = new BarDataSet(yVals1, "DataSet 1");

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

        BarData data = new BarData(xVals, dataSets);
        data.setValueTextSize(10f);
        data.setValueTypeface(tf);

        mChart.setData(data);
    }
 
Example #27
Source File: BarChartActivity.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * 生成柱状图的数据
 */
private BarData generateDataBar() {

    ArrayList<BarEntry> entries = new ArrayList<BarEntry>();

    for (int i = 0; i < 12; i++) {
        entries.add(new BarEntry((int) (Math.random() * 70) + 30, i));
    }

    BarDataSet d = new BarDataSet(entries, "New DataSet ");
    // 设置柱状图之间的间距
    d.setBarSpacePercent(20f);
    // 设置显示的柱状图的颜色
    d.setColors(ColorTemplate.VORDIPLOM_COLORS);
    // 设置高亮的透明度:当点击柱状图时显示的透明度
    d.setHighLightAlpha(255);

    BarData cd = new BarData(getMonths(), d);
    return cd;
}
 
Example #28
Source File: BarChart.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be
 * found in the charts data.  Performance-intensive code should use void getBarBounds(BarEntry, RectF) instead.
 *
 * @param e
 * @return
 */
public RectF getBarBounds(BarEntry e) {

    RectF bounds = new RectF();
    getBarBounds(e, bounds);

    return bounds;
}
 
Example #29
Source File: BarChart.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be
 * found in the charts data.  Performance-intensive code should use void getBarBounds(BarEntry, RectF) instead.
 *
 * @param e
 * @return
 */
public RectF getBarBounds(BarEntry e) {

    RectF bounds = new RectF();
    getBarBounds(e, bounds);

    return bounds;
}
 
Example #30
Source File: TimeLineView.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public void addData(HisData hisData) {
    hisData = DataUtils.calculateHisData(hisData, mData);
    CombinedData combinedData = mChartPrice.getData();
    LineData priceData = combinedData.getLineData();
    ILineDataSet priceSet = priceData.getDataSetByIndex(0);
    ILineDataSet aveSet = priceData.getDataSetByIndex(1);
    IBarDataSet volSet = mChartVolume.getData().getBarData().getDataSetByIndex(0);
    if (mData.contains(hisData)) {
        int index = mData.indexOf(hisData);
        priceSet.removeEntry(index);
        aveSet.removeEntry(index);
        volSet.removeEntry(index);
        mData.remove(index);
    }
    mData.add(hisData);
    priceSet.addEntry(new Entry(priceSet.getEntryCount(), (float) hisData.getClose()));
    aveSet.addEntry(new Entry(aveSet.getEntryCount(), (float) hisData.getAvePrice()));
    volSet.addEntry(new BarEntry(volSet.getEntryCount(), hisData.getVol(), hisData));

    mChartPrice.setVisibleXRange(MAX_COUNT, MIN_COUNT);
    mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT);

    mChartPrice.getXAxis().setAxisMaximum(combinedData.getXMax() + 1.5f);
    mChartVolume.getXAxis().setAxisMaximum(mChartVolume.getData().getXMax() + 1.5f);

    mChartPrice.notifyDataSetChanged();
    mChartPrice.invalidate();
    mChartVolume.notifyDataSetChanged();
    mChartVolume.invalidate();

    setDescription(mChartVolume, "成交量 " + hisData.getVol());
}