Java Code Examples for com.github.mikephil.charting.data.LineData#getDataSetCount()

The following examples show how to use com.github.mikephil.charting.data.LineData#getDataSetCount() . 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: DynamicalAddingActivity.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private void addDataSet() {

        LineData data = chart.getData();

        if (data == null) {
            chart.setData(new LineData());
        } else {
            int count = (data.getDataSetCount() + 1);
            int amount = data.getDataSetByIndex(0).getEntryCount();

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

            for (int i = 0; i < amount; i++) {
                values.add(new Entry(i, (float) (Math.random() * 50f) + 50f * count));
            }

            LineDataSet set = new LineDataSet(values, "DataSet " + count);
            set.setLineWidth(2.5f);
            set.setCircleRadius(4.5f);

            int color = colors[count % colors.length];

            set.setColor(color);
            set.setCircleColor(color);
            set.setHighLightColor(color);
            set.setValueTextSize(10f);
            set.setValueTextColor(color);

            data.addDataSet(set);
            data.notifyDataChanged();
            chart.notifyDataSetChanged();
            chart.invalidate();
        }
    }
 
Example 2
Source File: LineChartRenderer.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    LineData lineData = mChart.getLineData();
    mLineBuffers = new LineBuffer[lineData.getDataSetCount()];
    mCircleBuffers = new CircleBuffer[lineData.getDataSetCount()];

    for (int i = 0; i < mLineBuffers.length; i++) {
        LineDataSet set = lineData.getDataSetByIndex(i);
        mLineBuffers[i] = new LineBuffer(set.getEntryCount() * 4 - 4);
        mCircleBuffers[i] = new CircleBuffer(set.getEntryCount() * 2);
    }
}
 
Example 3
Source File: LineChartRenderer.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void initBuffers() {

    LineData lineData = mChart.getLineData();
    mLineBuffers = new LineBuffer[lineData.getDataSetCount()];
    mCircleBuffers = new CircleBuffer[lineData.getDataSetCount()];

    for (int i = 0; i < mLineBuffers.length; i++) {
        ILineDataSet set = lineData.getDataSetByIndex(i);
        mLineBuffers[i] = new LineBuffer(set.getEntryCount() * 4 - 4);
        mCircleBuffers[i] = new CircleBuffer(set.getEntryCount() * 2);
    }
}
 
Example 4
Source File: DynamicalAddingActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
private void addEntry() {

        LineData data = mChart.getData();
        
        if(data != null) {

            ILineDataSet set = data.getDataSetByIndex(0);
            // set.addEntry(...); // can be called as well

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

            // add a new x-value first
            data.addXValue(set.getEntryCount() + "");
            
            // choose a random dataSet
            int randomDataSetIndex = (int) (Math.random() * data.getDataSetCount());
            
            data.addEntry(new Entry((float) (Math.random() * 10) + 50f, set.getEntryCount()), randomDataSetIndex);

            // let the chart know it's data has changed
            mChart.notifyDataSetChanged();
            
            mChart.setVisibleXRangeMaximum(6);
            mChart.setVisibleYRangeMaximum(15, AxisDependency.LEFT);
//            
//            // this automatically refreshes the chart (calls invalidate())
            mChart.moveViewTo(data.getXValCount()-7, 50f, AxisDependency.LEFT);
        }
    }
 
Example 5
Source File: DynamicalAddingActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
private void addDataSet() {

        LineData data = mChart.getData();
        
        if(data != null) {

            int count = (data.getDataSetCount() + 1);

            // create 10 y-vals
            ArrayList<Entry> yVals = new ArrayList<Entry>();
            
            if(data.getXValCount() == 0) {
                // add 10 x-entries
                for (int i = 0; i < 10; i++) {
                    data.addXValue("" + (i+1));
                }
            }

            for (int i = 0; i < data.getXValCount(); i++) {
                yVals.add(new Entry((float) (Math.random() * 50f) + 50f * count, i));
            }

            LineDataSet set = new LineDataSet(yVals, "DataSet " + count);
            set.setLineWidth(2.5f);
            set.setCircleRadius(4.5f);

            int color = mColors[count % mColors.length];

            set.setColor(color);
            set.setCircleColor(color);
            set.setHighLightColor(color);
            set.setValueTextSize(10f);
            set.setValueTextColor(color);

            data.addDataSet(set);
            mChart.notifyDataSetChanged();
            mChart.invalidate();   
        }
    }
 
Example 6
Source File: LineChartRenderer.java    From NetKnight with Apache License 2.0 4 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    LineData lineData = mChart.getLineData();

    for (Highlight high : indices) {

        final int minDataSetIndex = high.getDataSetIndex() == -1
                ? 0
                : high.getDataSetIndex();
        final int maxDataSetIndex = high.getDataSetIndex() == -1
                ? lineData.getDataSetCount()
                : (high.getDataSetIndex() + 1);
        if (maxDataSetIndex - minDataSetIndex < 1) continue;

        for (int dataSetIndex = minDataSetIndex;
             dataSetIndex < maxDataSetIndex;
             dataSetIndex++) {

            ILineDataSet set = lineData.getDataSetByIndex(dataSetIndex);

            if (set == null || !set.isHighlightEnabled())
                continue;

            int xIndex = high.getXIndex(); // get the
            // x-position

            if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX())
                continue;

            final float yVal = set.getYValForXIndex(xIndex);
            if (Float.isNaN(yVal))
                continue;

            float y = yVal * mAnimator.getPhaseY(); // get
            // the
            // y-position

            float[] pts = new float[]{
                    xIndex, y
            };

            mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts);

            // draw the lines
            drawHighlightLines(c, pts, set);
        }
    }
}