Java 类com.github.mikephil.charting.data.Entry 实例源码

项目:pm-home-station    文件:ChartFragment.java   
private void addEntry(String label, int value) {
    LineData data = chart.getData();
    if (data != null) {
        int index;
        if (label.equals(pm1Label)) {
            index = 0;
        } else if (label.equals(pm25Label)) {
            index = 1;
        } else {
            index = 2;
        }
        ILineDataSet set = data.getDataSetByIndex(index);

        if (set == null) {
            set = createSet(label);
            data.addDataSet(set);
        }

        data.addEntry(new Entry(set.getEntryCount(), value), index);
    }
}
项目:DOUSalaries    文件:DataBaseHelper.java   
private LineData buildLineData(List<Entry> seniors, List<Entry> engineer,
                               List<Entry> juniors, String[] jobTitles ){
    List<ILineDataSet> sets = new ArrayList<>();
    if (!seniors.isEmpty()){
        LineDataSet dSenior = buildLineDataSet(seniors, jobTitles[0]);
        sets.add(dSenior);
    }
    if (!engineer.isEmpty()){
        LineDataSet dEngineer = buildLineDataSet(engineer, jobTitles[1]);
        dEngineer.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
        dEngineer.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
        sets.add(dEngineer);
    }
    if (!juniors.isEmpty()) {
        LineDataSet dJunior = buildLineDataSet(juniors, jobTitles[2]);
        dJunior.setColor(ColorTemplate.VORDIPLOM_COLORS[2]);
        dJunior.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[2]);
        sets.add(dJunior);//add data
    }
    return  new LineData(sets);
}
项目:DOUSalaries    文件:ExperienceMarker.java   
@Override
public void refreshContent(Entry e, Highlight highlight) {
    if (e instanceof CandleEntry) {
        CandleEntry ce = (CandleEntry) e;
        tvContent.setText(getContext().getString(R.string.salaries_format_salary,
                (int) ce.getHigh()));
    } else {
        EntryMarkerData data = (EntryMarkerData) e.getData();
        tvContent.setText(getContext().getString(R.string.exp_format_marker,
                String.valueOf(data.getValue()),
                String.valueOf(data.getCount())
                )
        );
    }
    super.refreshContent(e, highlight);
}
项目:Lunary-Ethereum-Wallet    文件:FragmentPrice.java   
private LineData getData(ArrayList<Entry> yVals) {
    LineDataSet set1 = new LineDataSet(yVals, "");
    set1.setLineWidth(1.45f);
    set1.setColor(Color.argb(240, 255, 255, 255));
    set1.setCircleColor(Color.WHITE);
    set1.setHighLightColor(Color.WHITE);
    set1.setFillColor(getResources().getColor(R.color.chartFilled));
    set1.setDrawCircles(false);
    set1.setDrawValues(false);
    set1.setDrawFilled(true);
    set1.setFillFormatter(new IFillFormatter() {
        @Override
        public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
            return priceChart.getAxisLeft().getAxisMinimum();
        }
    });

    LineData data = new LineData(set1);
    return data;
}
项目:GitHub    文件:BarChartActivity.java   
@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, AxisDependency.LEFT);

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

    Log.i("x-index",
            "low: " + mChart.getLowestVisibleX() + ", high: "
                    + mChart.getHighestVisibleX());

    MPPointF.recycleInstance(position);
}
项目:exchange-rates-mvvm    文件:LineChartExtensions.java   
@BindingAdapter({"bind:items"})
public static void populateDiagram(LineChart view, List<SingleValue> items) {

    if (null == items || items.size() == 0) {
        return;
    }
    List<Entry> entries = new ArrayList<>();
    for (int i = 0; i < items.size(); i++) {
        final SingleValue item = items.get(i);
        final Entry entry = new Entry(i, (float) item.getValue(), item);
        entries.add(entry);
    }
    LineDataSet dataSet = new LineDataSet(entries, view.getContext().getString(R.string.currency_value));
    LineData lineData = new LineData(dataSet);

    formatXAxisLabels(view, items);
    view.setData(lineData);
    view.invalidate();
}
项目:GitHub    文件:CombinedChartActivity.java   
private LineData generateLineData() {

        LineData d = new LineData();

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

        for (int index = 0; index < itemcount; index++)
            entries.add(new Entry(index + 0.5f, getRandom(15, 5)));

        LineDataSet set = new LineDataSet(entries, "Line DataSet");
        set.setColor(Color.rgb(240, 238, 70));
        set.setLineWidth(2.5f);
        set.setCircleColor(Color.rgb(240, 238, 70));
        set.setCircleRadius(5f);
        set.setFillColor(Color.rgb(240, 238, 70));
        set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
        set.setDrawValues(true);
        set.setValueTextSize(10f);
        set.setValueTextColor(Color.rgb(240, 238, 70));

        set.setAxisDependency(YAxis.AxisDependency.LEFT);
        d.addDataSet(set);

        return d;
    }
项目:GitHub    文件:DynamicalAddingActivity.java   
private void removeLastEntry() {

        LineData data = mChart.getData();

        if (data != null) {

            ILineDataSet set = data.getDataSetByIndex(0);

            if (set != null) {

                Entry e = set.getEntryForXValue(set.getEntryCount() - 1, Float.NaN);

                data.removeEntry(e, 0);
                // or remove by index
                // mData.removeEntryByXValue(xIndex, dataSetIndex);
                data.notifyDataChanged();
                mChart.notifyDataSetChanged();
                mChart.invalidate();
            }
        }
    }
项目:igrow-android    文件:EnvironmentalSensorDetailFragment.java   
protected ScatterData generateScatterData() {

        ScatterData d = new ScatterData();

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

        for (float index = 0; index < itemcount; index += 0.5f)
            entries.add(new Entry(index + 0.25f, getRandom(10, 55)));

        ScatterDataSet set = new ScatterDataSet(entries, "Scatter DataSet");
        set.setColors(ColorTemplate.MATERIAL_COLORS);
        set.setScatterShapeSize(7.5f);
        set.setDrawValues(false);
        set.setValueTextSize(10f);
        d.addDataSet(set);

        return d;
    }
项目:AndiCar    文件:LineChartComponent.java   
@Override
public void refreshContent(Entry e, Highlight highlight) {
    String content;
    if (mWhatData == SHOW_FUEL_PRICE_EVOLUTION)
        content = String.format(mCtx.getString(R.string.line_chart_fuel_price_marker_text),
            Utils.numberToString(e.getY(), true, ConstantValues.DECIMALS_PRICE, ConstantValues.ROUNDING_MODE_PRICE),
            Utils.getFormattedDateTime((mChartDates.get((int) e.getX())) * 1000, true));
    else
        content = Utils.numberToString(e.getY(), true, ConstantValues.DECIMALS_FUEL_EFF, ConstantValues.ROUNDING_MODE_FUEL_EFF);

    tvContent.setText(content);

    //resize the marker view.
    //see https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/main/java/com/github/mikephil/charting/components/MarkerView.java
    measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
项目:igrow-android    文件:EnvironmentalSensorDetailFragment.java   
private LineData generateLineData() {

        LineData d = new LineData();

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

        for (int index = 0; index < itemcount; index++)
            entries.add(new Entry(index + 0.5f, getRandom(15, 5)));

        LineDataSet set = new LineDataSet(entries, "Line DataSet");
        set.setColor(Color.rgb(240, 238, 70));
        set.setLineWidth(2.5f);
        set.setCircleColor(Color.rgb(240, 238, 70));
        set.setCircleRadius(5f);
        set.setFillColor(Color.rgb(240, 238, 70));
        set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
        set.setDrawValues(true);
        set.setValueTextSize(10f);
        set.setValueTextColor(Color.rgb(240, 238, 70));

        set.setAxisDependency(YAxis.AxisDependency.LEFT);
        d.addDataSet(set);

        return d;
    }
项目:GitHub    文件:InvertedLineChartActivity.java   
private void setData(int count, float range) {

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

        for (int i = 0; i < count; i++) {
            float xVal = (float) (Math.random() * range);
            float yVal = (float) (Math.random() * range);
            entries.add(new Entry(xVal, yVal));
        }

        // sort by x-value
        Collections.sort(entries, new EntryXComparator());

        // create a dataset and give it a type
        LineDataSet set1 = new LineDataSet(entries, "DataSet 1");

        set1.setLineWidth(1.5f);
        set1.setCircleRadius(4f);

        // create a data object with the datasets
        LineData data = new LineData(set1);

        // set data
        mChart.setData(data);
    }
项目:GitHub    文件:HorizontalBarChartActivity.java   
@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);
}
项目:SOS-The-Healthcare-Companion    文件:OverviewFragment.java   
private LineData generateCholesterolData() {
    List<String> xVals = new ArrayList<>();
    List<Entry> yVals = new ArrayList<>();

    for (int i = 0; i < presenter.getCholesterolReadings().size(); i++) {
        float val = Float.parseFloat(presenter.getCholesterolReadings().get(i).toString());
        yVals.add(new Entry(val, i));
    }

    xVals.clear();
    for (int i = 0; i < presenter.getCholesterolReadingsDateTime().size(); i++) {
        String date = presenter.convertDate(presenter.getCholesterolReadingsDateTime().get(i));
        xVals.add(date + "");
    }

    // create a data object with the datasets
    return new LineData(xVals,
            generateLineDataSet(yVals, getResources().getColor(R.color.glucosio_fab_cholesterol)));
}
项目:xwallet    文件:WalletFragment.java   
/**
 *
 * @param balance
 */
public void updateBalance(String balance) {
   // _balanceTxt.setText(balance);
    _lastBalance = balance;
    _walletFragView.updateBalance(balance);

    if(_btcChartEntries != null && !_btcChartEntries.isEmpty()) {
        Entry latestValue = _btcChartEntries.get(_btcChartEntries.size() - 1);
        Double actualBalance = Double.parseDouble(balance);
        Locale locale = new Locale("en", "US");
        NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);

        double conversionValue = actualBalance * latestValue.getY();
        String subBalance = String.format(Locale.getDefault(), "(%s$)", currencyFormatter.format(conversionValue));
        //_subBalanceTxt.setText(subBalance);
        _walletFragView.updateConversion(subBalance);
    }
}
项目:android-ponewheel    文件:RideDetailActivity.java   
private void addDragListenerMarkerMaker(LineChart speedChart) {
    speedChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry entry, Highlight h) {
            Long entryX = (long) entry.getX();
            if (timeLocationMap.containsKey(entryX)) {
                clearAllMarkersFromMap();
                LatLng latLng = timeLocationMap.get(entryX);
                mapMarkers.add(googleMap.addMarker(new MarkerOptions().position(latLng)));
            }
        }

        @Override
        public void onNothingSelected() {
            clearAllMarkersFromMap();
        }
    });
}
项目:DOUSalaries    文件:LineChartItem.java   
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder ) {
    final LineChartHolder lineHolder = (LineChartHolder) holder;
    lineHolder.language.setText(title);
    ChartHelper.setLineChart(context, lineHolder.chart, getChartData(), month, typeface);
    lineHolder.chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry e, Highlight h) {
            if (e == null){
                return;
            }
            Timber.d("onValueSelected Selected:%s dataSet:%d", e.toString(), h.getDataSetIndex());
            lineHolder.chart.setDrawMarkers(true);
        }

        @Override
        public void onNothingSelected() {
            Timber.d("Nothing selected.");
        }
    });
}
项目:SOS-The-Healthcare-Companion    文件:OverviewFragment.java   
private LineData generateA1cData() {
    ArrayList<String> xVals = new ArrayList<>();
    ArrayList<Entry> yVals = new ArrayList<>();

    for (int i = 0; i < presenter.getA1cReadings().size(); i++) {
        float val = Float.parseFloat(presenter.getA1cReadings().get(i).toString());
        yVals.add(new Entry(val, i));
    }

    xVals.clear();
    for (int i = 0; i < presenter.getA1cReadingsDateTime().size(); i++) {
        String date = presenter.convertDate(presenter.getA1cReadingsDateTime().get(i));
        xVals.add(date + "");
    }

    // create a data object with the datasets
    return new LineData(xVals,
            generateLineDataSet(yVals, getResources().getColor(R.color.glucosio_fab_HB1AC)));
}
项目:SOS-The-Healthcare-Companion    文件:OverviewFragment.java   
private LineData generateKetonesData() {
    List<String> xVals = new ArrayList<>();
    List<Entry> yVals = new ArrayList<>();

    for (int i = 0; i < presenter.getKetonesReadings().size(); i++) {
        float val = Float.parseFloat(presenter.getKetonesReadings().get(i).toString());
        yVals.add(new Entry(val, i));
    }

    xVals.clear();
    for (int i = 0; i < presenter.getKetonesReadingsDateTime().size(); i++) {
        String date = presenter.convertDate(presenter.getKetonesReadingsDateTime().get(i));
        xVals.add(date + "");
    }

    // create a data object with the datasets
    return new LineData(xVals,
            generateLineDataSet(yVals, getResources().getColor(R.color.glucosio_fab_ketones)));
}
项目:Demos    文件:ChartUtils.java   
/**
 * 更新图表
 *
 * @param chart     图表
 * @param values    数据
 * @param valueType 数据类型
 */
public static void notifyDataSetChanged(LineChart chart, List<Entry> values,
                                        final int valueType) {
    chart.getXAxis().setValueFormatter(new IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return xValuesProcess(valueType)[(int) value];
        }
    });

    chart.invalidate();
    setChartData(chart, values);
}
项目:Demos    文件:LineChartActivity.java   
private List<Entry> getData() {
    List<Entry> values = new ArrayList<>();
    values.add(new Entry(0, 15));
    values.add(new Entry(1, 15));
    values.add(new Entry(2, 15));
    values.add(new Entry(3, 20));
    values.add(new Entry(4, 25));
    values.add(new Entry(5, 20));
    values.add(new Entry(6, 20));
    return values;
}
项目:GitHub    文件:BarLineChartBase.java   
/**
 * returns the Entry object displayed at the touched position of the chart
 *
 * @param x
 * @param y
 * @return
 */
public Entry getEntryByTouchPoint(float x, float y) {
    Highlight h = getHighlightByTouchPoint(x, y);
    if (h != null) {
        return mData.getEntryForHighlight(h);
    }
    return null;
}
项目:GitHub    文件:Chart.java   
/**
 * Highlights the value selected by touch gesture. Unlike
 * highlightValues(...), this generates a callback to the
 * OnChartValueSelectedListener.
 *
 * @param high         - the highlight object
 * @param callListener - call the listener
 */
public void highlightValue(Highlight high, boolean callListener) {

    Entry e = null;

    if (high == null)
        mIndicesToHighlight = null;
    else {

        if (mLogEnabled)
            Log.i(LOG_TAG, "Highlighted: " + high.toString());

        e = mData.getEntryForHighlight(high);
        if (e == null) {
            mIndicesToHighlight = null;
            high = null;
        } else {

            // set the indices to highlight
            mIndicesToHighlight = new Highlight[]{
                    high
            };
        }
    }

    setLastHighlighted(mIndicesToHighlight);

    if (callListener && mSelectionListener != null) {

        if (!valuesToHighlight())
            mSelectionListener.onNothingSelected();
        else {
            // notify the listener
            mSelectionListener.onValueSelected(e, high);
        }
    }

    // redraw the chart
    invalidate();
}
项目:GitHub    文件:Chart.java   
/**
 * draws all MarkerViews on the highlighted positions
 */
protected void drawMarkers(Canvas canvas) {

    // if there is no marker view or drawing marker is disabled
    if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight())
        return;

    for (int i = 0; i < mIndicesToHighlight.length; i++) {

        Highlight highlight = mIndicesToHighlight[i];

        IDataSet set = mData.getDataSetByIndex(highlight.getDataSetIndex());

        Entry e = mData.getEntryForHighlight(mIndicesToHighlight[i]);
        int entryIndex = set.getEntryIndex(e);

        // make sure entry not null
        if (e == null || entryIndex > set.getEntryCount() * mAnimator.getPhaseX())
            continue;

        float[] pos = getMarkerPosition(highlight);

        // check bounds
        if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
            continue;

        // callbacks to update the content
        mMarker.refreshContent(e, highlight);

        // draw the marker
        mMarker.draw(canvas, pos[0], pos[1]);
    }
}
项目:DOUSalaries    文件:DataBaseHelper.java   
private LineDataSet buildLineDataSet(List<Entry> entries, String title){
    LineDataSet result = new LineDataSet(entries, title);
    result.setLineWidth(2.5f);
    result.setCircleRadius(4.5f);
    result.setHighLightColor(Color.rgb(244, 117, 117));
    result.setDrawValues(false);//draw value
    return result;
}
项目:Synapse    文件:TrainedModelItem.java   
public List<Entry> getEntries() {
    if (mEntries == null) {
        mEntries = format();
    }

    return mEntries;
}
项目:GitHub    文件:LineChartRenderer.java   
/**
 * Generates a path that is used for filled drawing.
 *
 * @param dataSet    The dataset from which to read the entries.
 * @param startIndex The index from which to start reading the dataset
 * @param endIndex   The index from which to stop reading the dataset
 * @param outputPath The path object that will be assigned the chart data.
 * @return
 */
private void generateFilledPath(final ILineDataSet dataSet, final int startIndex, final int endIndex, final Path outputPath) {

    final float fillMin = dataSet.getFillFormatter().getFillLinePosition(dataSet, mChart);
    final float phaseY = mAnimator.getPhaseY();
    final boolean isDrawSteppedEnabled = dataSet.getMode() == LineDataSet.Mode.STEPPED;

    final Path filled = outputPath;
    filled.reset();

    final Entry entry = dataSet.getEntryForIndex(startIndex);

    filled.moveTo(entry.getX(), fillMin);
    filled.lineTo(entry.getX(), entry.getY() * phaseY);

    // create a new path
    Entry currentEntry = null;
    Entry previousEntry = null;
    for (int x = startIndex + 1; x <= endIndex; x++) {

        currentEntry = dataSet.getEntryForIndex(x);

        if (isDrawSteppedEnabled && previousEntry != null) {
            filled.lineTo(currentEntry.getX(), previousEntry.getY() * phaseY);
        }

        filled.lineTo(currentEntry.getX(), currentEntry.getY() * phaseY);

        previousEntry = currentEntry;
    }

    // close up
    if (currentEntry != null) {
        filled.lineTo(currentEntry.getX(), fillMin);
    }

    filled.close();
}
项目:GitHub    文件:BarLineScatterCandleBubbleRenderer.java   
/**
 * Checks if the provided entry object is in bounds for drawing considering the current animation phase.
 *
 * @param e
 * @param set
 * @return
 */
protected boolean isInBoundsX(Entry e, IBarLineScatterCandleBubbleDataSet set) {

    if (e == null)
        return false;

    float entryIndex = set.getEntryIndex(e);

    if (e == null || entryIndex >= set.getEntryCount() * mAnimator.getPhaseX()) {
        return false;
    } else {
        return true;
    }
}
项目:SQLite-Performance    文件:TestSuiteFragment.java   
public void runTests() {
    for (TestCaseRunner runner : mRunners) {
        runner.cancel(true);
    }
    mRunners.clear();

    mChart.clear();

    BarData data = new BarData();
    mChart.setData(data);

    MetricsVariableAxisFormatter formatter = new MetricsVariableAxisFormatter(getMetricsTransformer());

    setupYAxes(mChart);
    setupXAxis(mChart, formatter);
    setupDescription(mChart);

    Legend legend = mChart.getLegend();
    legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    legend.setWordWrapEnabled(true);
    legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    legend.setDrawInside(false);

    mChart.invalidate();

    Map<TestScenarioMetadata, TestCase[]> scenarios = getTestScenarios();
    for (Map.Entry<TestScenarioMetadata, TestCase[]> scenario : scenarios.entrySet()) {
        TestScenarioMetadata d = scenario.getKey();

        TestCaseRunner r = new TestCaseRunner(d.iterations, mChart, d.title, d.color, formatter);
        r.executeOnExecutor(TestCaseRunner.SERIAL_EXECUTOR, scenario.getValue());
        mRunners.add(r);
    }
}
项目:Synapse    文件:ModelDetailActivity.java   
private boolean setUpChart(@NonNull Model model) {
    final double[] accuracies = model.getAccuracies();

    if (accuracies == null
            || accuracies.length == 0
            || model.getStepEpoch() < 1) {
        return false;
    }

    mAccuracyData.clear();

    for (int i = 0, len = model.getStepEpoch(); i < len; ++i) {
        mAccuracyData.add(new Entry(i + 1, (float) accuracies[i]));
    }

    final LineDataSet set = new LineDataSet(mAccuracyData, getString(R.string.text_chart_left_axis));

    set.setMode(LineDataSet.Mode.LINEAR);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setColor(ContextCompat.getColor(this, R.color.chart_left_axis));
    set.setCircleColor(ContextCompat.getColor(this, R.color.chart_left_axis));
    set.setHighLightColor(ContextCompat.getColor(this, R.color.chart_highlight));
    set.setCircleColorHole(Color.WHITE);
    set.setDrawCircleHole(true);
    set.setHighlightEnabled(true);
    set.setLineWidth(2F);
    set.setCircleRadius(3F);
    set.setDrawFilled(false);

    final LineData group = new LineData(set);
    group.setDrawValues(false);

    setXAxis(model.getEpochs());

    mChart.setData(group);
    mChart.invalidate();
    startChartAnimate();

    return true;
}
项目:GitHub    文件:EntryXComparator.java   
@Override
public int compare(Entry entry1, Entry entry2) {
    float diff = entry1.getX() - entry2.getX();

    if (diff == 0f) return 0;
    else {
        if (diff > 0f) return 1;
        else return -1;
    }
}
项目:GitHub    文件:Transformer.java   
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the SCATTERCHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX,
                                                float phaseY, int from, int to) {

    final int count = (int) ((to - from) * phaseX + 1) * 2;

    if (valuePointsForGenerateTransformedValuesScatter.length != count) {
        valuePointsForGenerateTransformedValuesScatter = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesScatter;

    for (int j = 0; j < count; j += 2) {

        Entry e = data.getEntryForIndex(j / 2 + from);

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getY() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
项目:GitHub    文件:Transformer.java   
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the BUBBLECHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesBubble(IBubbleDataSet data, float phaseY, int from, int to) {

    final int count = (to - from + 1) * 2; // (int) Math.ceil((to - from) * phaseX) * 2;

    if (valuePointsForGenerateTransformedValuesBubble.length != count) {
        valuePointsForGenerateTransformedValuesBubble = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesBubble;

    for (int j = 0; j < count; j += 2) {

        Entry e = data.getEntryForIndex(j / 2 + from);

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getY() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
项目:GitHub    文件:Transformer.java   
/**
 * Transforms an List of Entry into a float array containing the x and
 * y values transformed with all matrices for the LINECHART.
 *
 * @param data
 * @return
 */
public float[] generateTransformedValuesLine(ILineDataSet data,
                                             float phaseX, float phaseY,
                                             int min, int max) {

    final int count = ((int) ((max - min) * phaseX) + 1) * 2;

    if (valuePointsForGenerateTransformedValuesLine.length != count) {
        valuePointsForGenerateTransformedValuesLine = new float[count];
    }
    float[] valuePoints = valuePointsForGenerateTransformedValuesLine;

    for (int j = 0; j < count; j += 2) {

        Entry e = data.getEntryForIndex(j / 2 + min);

        if (e != null) {
            valuePoints[j] = e.getX();
            valuePoints[j + 1] = e.getY() * phaseY;
        } else {
            valuePoints[j] = 0;
            valuePoints[j + 1] = 0;
        }
    }

    getValueToPixelMatrix().mapPoints(valuePoints);

    return valuePoints;
}
项目:GitHub    文件:ChartHighlighter.java   
/**
 * An array of `Highlight` objects corresponding to the selected xValue and dataSetIndex.
 *
 * @param set
 * @param dataSetIndex
 * @param xVal
 * @param rounding
 * @return
 */
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {

    ArrayList<Highlight> highlights = new ArrayList<>();

    //noinspection unchecked
    List<Entry> entries = set.getEntriesForXValue(xVal);
    if (entries.size() == 0) {
        // Try to find closest x-value and take all entries for that x-value
        final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
        if (closest != null)
        {
            //noinspection unchecked
            entries = set.getEntriesForXValue(closest.getX());
        }
    }

    if (entries.size() == 0)
        return highlights;

    for (Entry e : entries) {
        MPPointD pixels = mChart.getTransformer(
                set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());

        highlights.add(new Highlight(
                e.getX(), e.getY(),
                (float) pixels.x, (float) pixels.y,
                dataSetIndex, set.getAxisDependency()));
    }

    return highlights;
}
项目:GitHub    文件:HorizontalBarHighlighter.java   
@Override
protected List<Highlight> buildHighlights(IDataSet set, int dataSetIndex, float xVal, DataSet.Rounding rounding) {

    ArrayList<Highlight> highlights = new ArrayList<>();

    //noinspection unchecked
    List<Entry> entries = set.getEntriesForXValue(xVal);
    if (entries.size() == 0) {
        // Try to find closest x-value and take all entries for that x-value
        final Entry closest = set.getEntryForXValue(xVal, Float.NaN, rounding);
        if (closest != null)
        {
            //noinspection unchecked
            entries = set.getEntriesForXValue(closest.getX());
        }
    }

    if (entries.size() == 0)
        return highlights;

    for (Entry e : entries) {
        MPPointD pixels = mChart.getTransformer(
                set.getAxisDependency()).getPixelForValues(e.getY(), e.getX());

        highlights.add(new Highlight(
                e.getX(), e.getY(),
                (float) pixels.x, (float) pixels.y,
                dataSetIndex, set.getAxisDependency()));
    }

    return highlights;
}
项目:GitHub    文件:MarkerView.java   
@Override
public void refreshContent(Entry e, Highlight highlight) {

    measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    layout(0, 0, getMeasuredWidth(), getMeasuredHeight());

}
项目:GitHub    文件:DataSetTest.java   
@Test
public void testGetEntryForXValue() {

    List<Entry> entries = new ArrayList<Entry>();
    entries.add(new Entry(10, 10));
    entries.add(new Entry(15, 5));
    entries.add(new Entry(21, 5));

    ScatterDataSet set = new ScatterDataSet(entries, "");

    Entry closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.CLOSEST);
    assertEquals(15, closest.getX(), 0.01f);
    assertEquals(5, closest.getY(), 0.01f);

    closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.DOWN);
    assertEquals(15, closest.getX(), 0.01f);
    assertEquals(5, closest.getY(), 0.01f);

    closest = set.getEntryForXValue(15, Float.NaN, DataSet.Rounding.DOWN);
    assertEquals(15, closest.getX(), 0.01f);
    assertEquals(5, closest.getY(), 0.01f);

    closest = set.getEntryForXValue(14, Float.NaN, DataSet.Rounding.DOWN);
    assertEquals(10, closest.getX(), 0.01f);
    assertEquals(10, closest.getY(), 0.01f);

    closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.UP);
    assertEquals(21, closest.getX(), 0.01f);
    assertEquals(5, closest.getY(), 0.01f);

    closest = set.getEntryForXValue(21, Float.NaN, DataSet.Rounding.UP);
    assertEquals(21, closest.getX(), 0.01f);
    assertEquals(5, closest.getY(), 0.01f);

    closest = set.getEntryForXValue(21, Float.NaN, DataSet.Rounding.CLOSEST);
    assertEquals(21, closest.getX(), 0.01f);
    assertEquals(5, closest.getY(), 0.01f);
}
项目:GitHub    文件:StackedBarActivity.java   
@Override
public void onValueSelected(Entry e, Highlight h) {

    BarEntry entry = (BarEntry) e;

    if (entry.getYVals() != null)
        Log.i("VAL SELECTED", "Value: " + entry.getYVals()[h.getStackIndex()]);
    else
        Log.i("VAL SELECTED", "Value: " + entry.getY());
}
项目:GitHub    文件:StackedBarActivityNegative.java   
@Override
public void onValueSelected(Entry e, Highlight h) {

    BarEntry entry = (BarEntry) e;
    Log.i("VAL SELECTED",
            "Value: " + Math.abs(entry.getYVals()[h.getStackIndex()]));
}