com.github.mikephil.charting.charts.ScatterChart Java Examples

The following examples show how to use com.github.mikephil.charting.charts.ScatterChart. 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: ScatterDataSet.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
public static IShapeRenderer getRendererForShape(ScatterChart.ScatterShape shape) {

        switch (shape) {
            case SQUARE:
                return new SquareShapeRenderer();
            case CIRCLE:
                return new CircleShapeRenderer();
            case TRIANGLE:
                return new TriangleShapeRenderer();
            case CROSS:
                return new CrossShapeRenderer();
            case X:
                return new XShapeRenderer();
            case CHEVRON_UP:
                return new ChevronUpShapeRenderer();
            case CHEVRON_DOWN:
                return new ChevronDownShapeRenderer();
        }

        return null;
    }
 
Example #2
Source File: SimpleFragment.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
protected ScatterData generateScatterData(int dataSets, float range, int count) {

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

        ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes();

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

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

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

            ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i));
            ds.setScatterShapeSize(12f);
            ds.setScatterShape(shapes[i % shapes.length]);
            ds.setColors(ColorTemplate.COLORFUL_COLORS);
            ds.setScatterShapeSize(9f);
            sets.add(ds);
        }

        ScatterData d = new ScatterData(sets);
        d.setValueTypeface(tf);
        return d;
    }
 
Example #3
Source File: RealmScatterDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 6 votes vote down vote up
public static IShapeRenderer getRendererForShape(ScatterChart.ScatterShape shape) {

        switch (shape) {
            case SQUARE:
                return new SquareShapeRenderer();
            case CIRCLE:
                return new CircleShapeRenderer();
            case TRIANGLE:
                return new TriangleShapeRenderer();
            case CROSS:
                return new CrossShapeRenderer();
            case X:
                return new XShapeRenderer();
            case CHEVRON_UP:
                return new ChevronUpShapeRenderer();
            case CHEVRON_DOWN:
                return new ChevronDownShapeRenderer();
        }

        return null;
    }
 
Example #4
Source File: AccelerometerFragment.java    From walt with Apache License 2.0 6 votes vote down vote up
private void drawLatencyChart(List<Entry> phoneEntriesShifted, List<Entry> waltEntries) {
    final ScatterDataSet dataSetWalt =
            new ScatterDataSet(waltEntries, "WALT Events");
    dataSetWalt.setColor(Color.BLUE);
    dataSetWalt.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
    dataSetWalt.setScatterShapeSize(8f);

    final ScatterDataSet dataSetPhoneShifted =
            new ScatterDataSet(phoneEntriesShifted, "Phone Events Shifted");
    dataSetPhoneShifted.setColor(Color.RED);
    dataSetPhoneShifted.setScatterShapeSize(10f);
    dataSetPhoneShifted.setScatterShape(ScatterChart.ScatterShape.X);

    final ScatterData scatterData = new ScatterData(dataSetWalt, dataSetPhoneShifted);
    final Description desc = new Description();
    desc.setText("");
    desc.setTextSize(12f);
    latencyChart.setDescription(desc);
    latencyChart.setData(scatterData);
    latencyChart.invalidate();
    latencyChartLayout.setVisibility(View.VISIBLE);
}
 
Example #5
Source File: AccelerometerFragment.java    From walt with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    logger = SimpleLogger.getInstance(getContext());
    waltDevice = WaltDevice.getInstance(getContext());

    // Inflate the layout for this fragment
    final View view = inflater.inflate(R.layout.fragment_accelerometer, container, false);
    logTextView = (TextView) view.findViewById(R.id.txt_log);
    startButton = view.findViewById(R.id.button_start);
    latencyChart = (ScatterChart) view.findViewById(R.id.latency_chart);
    latencyChartLayout = view.findViewById(R.id.latency_chart_layout);
    logTextView.setMovementMethod(new ScrollingMovementMethod());
    view.findViewById(R.id.button_close_chart).setOnClickListener(this);
    sensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
    accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (accelerometer == null) {
        logger.log("ERROR! Accelerometer sensor not found");
    }
    return view;
}
 
Example #6
Source File: DragLatencyFragment.java    From walt with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    logger = SimpleLogger.getInstance(getContext());
    waltDevice = WaltDevice.getInstance(getContext());

    // Inflate the layout for this fragment
    final View view = inflater.inflate(R.layout.fragment_drag_latency, container, false);
    logTextView = (TextView) view.findViewById(R.id.txt_log_drag_latency);
    startButton = view.findViewById(R.id.button_start_drag);
    restartButton = view.findViewById(R.id.button_restart_drag);
    finishButton = view.findViewById(R.id.button_finish_drag);
    touchCatcher = (TouchCatcherView) view.findViewById(R.id.tap_catcher);
    crossCountsView = (TextView) view.findViewById(R.id.txt_cross_counts);
    dragCountsView = (TextView) view.findViewById(R.id.txt_drag_counts);
    latencyChart = (ScatterChart) view.findViewById(R.id.latency_chart);
    latencyChartLayout = view.findViewById(R.id.latency_chart_layout);
    logTextView.setMovementMethod(new ScrollingMovementMethod());
    view.findViewById(R.id.button_close_chart).setOnClickListener(this);
    restartButton.setEnabled(false);
    finishButton.setEnabled(false);
    return view;
}
 
Example #7
Source File: RealmDatabaseActivityScatter.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
private void setData() {

        RealmResults<RealmDemoData> result = mRealm.allObjects(RealmDemoData.class);

        RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "value", "xIndex");
        set.setLabel("Realm ScatterDataSet");
        set.setScatterShapeSize(9f);
        set.setColor(ColorTemplate.rgb("#CDDC39"));
        set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);

        ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
        dataSets.add(set); // add the dataset

        // create a data object with the dataset list
        RealmScatterData data = new RealmScatterData(result, "xValue", dataSets);
        styleData(data);

        // set data
        mChart.setData(data);
        mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
    }
 
Example #8
Source File: SimpleFragment.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
protected ScatterData generateScatterData(int dataSets, float range, int count) {
    
    ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
    
    ScatterShape[] shapes = ScatterChart.getAllPossibleShapes();
    
    for(int i = 0; i < dataSets; i++) {
       
        ArrayList<Entry> entries = new ArrayList<Entry>();
        
        for(int j = 0; j < count; j++) {        
            entries.add(new Entry((float) (Math.random() * range) + range / 4, j));
        }
        
        ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i));
        ds.setScatterShapeSize(12f);
        ds.setScatterShape(shapes[i % shapes.length]);
        ds.setColors(ColorTemplate.COLORFUL_COLORS);
        ds.setScatterShapeSize(9f);
        sets.add(ds);
    }
    
    ScatterData d = new ScatterData(ChartData.generateXVals(0, count), sets);
    d.setValueTypeface(tf);
    return d;
}
 
Example #9
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void initScatter() {
    final ScatterChart scatterChart = getScatterChart();
    if(scatterChart == null) {
        return;
    }
    scatterChart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Show
            AlertDialog.Builder builder = new AlertDialog.Builder(CalibrationLinearityActivity.this);
            builder.setTitle(CalibrationLinearityActivity.this.getText(R.string.calibration_select_frequency));
            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(CalibrationLinearityActivity.this,
                    R.array.calibrate_type_list_array, android.R.layout.simple_selectable_list_item);
            builder.setAdapter(adapter,
                    new ItemActionOnClickListener(CalibrationLinearityActivity.this, scatterChart));
            builder.show();
        }
    });

    scatterChart.setDescription("");

    scatterChart.setDrawGridBackground(false);

    scatterChart.setMaxVisibleValueCount(200);

    Legend l = scatterChart.getLegend();
    l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
    l.setTextColor(Color.WHITE);

    YAxis yl = scatterChart.getAxisLeft();
    yl.setTextColor(Color.WHITE);
    yl.setGridColor(Color.WHITE);
    scatterChart.getAxisRight().setEnabled(false);

    XAxis xl = scatterChart.getXAxis();
    xl.setDrawGridLines(false);
    xl.setTextColor(Color.WHITE);
    xl.setGridColor(Color.WHITE);
}
 
Example #10
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private ScatterChart getScatterChart() {
    View view = ((ViewPagerAdapter)viewPager.getAdapter()).getItem(PAGE_SCATTER_CHART).getView();
    if(view != null) {
        return (ScatterChart) view.findViewById(R.id.autoCalibrationScatterChart);
    } else {
        return null;
    }
}
 
Example #11
Source File: DragLatencyFragment.java    From walt with Apache License 2.0 5 votes vote down vote up
private void drawLatencyGraph(double[] ft, double[] fy, double[] lt, double averageBestShift) {
    final ArrayList<Entry> touchEntries = new ArrayList<>();
    final ArrayList<Entry> laserEntries = new ArrayList<>();
    final double[] laserT = new double[lt.length];
    for (int i = 0; i < ft.length; i++) {
        touchEntries.add(new Entry((float) ft[i], (float) fy[i]));
    }
    for (int i = 0; i < lt.length; i++) {
        laserT[i] = lt[i] + averageBestShift;
    }
    final double[] laserY = Utils.interp(laserT, ft, fy);
    for (int i = 0; i < laserY.length; i++) {
        laserEntries.add(new Entry((float) laserT[i], (float) laserY[i]));
    }

    final ScatterDataSet dataSetTouch = new ScatterDataSet(touchEntries, "Touch Events");
    dataSetTouch.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
    dataSetTouch.setScatterShapeSize(8f);

    final ScatterDataSet dataSetLaser = new ScatterDataSet(laserEntries,
            String.format(Locale.US, "Laser Events  Latency=%.1f ms", averageBestShift));
    dataSetLaser.setColor(Color.RED);
    dataSetLaser.setScatterShapeSize(10f);
    dataSetLaser.setScatterShape(ScatterChart.ScatterShape.X);

    final ScatterData scatterData = new ScatterData(dataSetTouch, dataSetLaser);
    final Description desc = new Description();
    desc.setText("Y-Position [pixels] vs. Time [ms]");
    desc.setTextSize(12f);
    latencyChart.setDescription(desc);
    latencyChart.setData(scatterData);
    latencyChartLayout.setVisibility(View.VISIBLE);
}
 
Example #12
Source File: RealmDatabaseActivityScatter.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_scatterchart_noseekbar);

    mChart = (ScatterChart) findViewById(R.id.chart1);
    setup(mChart);

    mChart.getAxisLeft().setDrawGridLines(false);
    mChart.getXAxis().setDrawGridLines(false);
    mChart.setPinchZoom(true);
}
 
Example #13
Source File: ScatterChartFrag.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_scatter, container, false);
    
    mChart = (ScatterChart) v.findViewById(R.id.scatterChart1);
    mChart.setDescription("");
    
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
    
    MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);

    mChart.setMarkerView(mv);

    mChart.setDrawGridBackground(false);
    mChart.setData(generateScatterData(6, 10000, 200));
    
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(true);
    xAxis.setPosition(XAxisPosition.BOTTOM);
    
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setTypeface(tf);
    rightAxis.setDrawGridLines(false);
    
    Legend l = mChart.getLegend();
    l.setWordWrapEnabled(true);
    l.setTypeface(tf);
    l.setFormSize(14f);
    l.setTextSize(9f);
    
    // increase the space between legend & bottom and legend & content
    l.setYOffset(13f);       
    mChart.setExtraBottomOffset(16f);
    
    return v;
}
 
Example #14
Source File: ScatterDataSet.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public static IShapeRenderer getRendererForShape(ScatterChart.ScatterShape shape) {

        switch (shape) {
            case SQUARE: return new SquareShapeRenderer();
            case CIRCLE: return new CircleShapeRenderer();
            case TRIANGLE: return new TriangleShapeRenderer();
            case CROSS: return new CrossShapeRenderer();
            case X: return new XShapeRenderer();
            case CHEVRON_UP: return new ChevronUpShapeRenderer();
            case CHEVRON_DOWN: return new ChevronDownShapeRenderer();
        }

        return null;
    }
 
Example #15
Source File: ScatterDataSet.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public static IShapeRenderer getRendererForShape(ScatterChart.ScatterShape shape) {

        switch (shape) {
            case SQUARE: return new SquareShapeRenderer();
            case CIRCLE: return new CircleShapeRenderer();
            case TRIANGLE: return new TriangleShapeRenderer();
            case CROSS: return new CrossShapeRenderer();
            case X: return new XShapeRenderer();
            case CHEVRON_UP: return new ChevronUpShapeRenderer();
            case CHEVRON_DOWN: return new ChevronDownShapeRenderer();
        }

        return null;
    }
 
Example #16
Source File: ScatterChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_scatterchart);

    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);

    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarX.setOnSeekBarChangeListener(this);

    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarY.setOnSeekBarChangeListener(this);

    mChart = (ScatterChart) findViewById(R.id.chart1);
    mChart.setDescription("");

    tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    mChart.setOnChartValueSelectedListener(this);

    mChart.setDrawGridBackground(false);

    mChart.setTouchEnabled(true);

    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);

    mChart.setMaxVisibleValueCount(200);
    mChart.setPinchZoom(true);

    mSeekBarX.setProgress(45);
    mSeekBarY.setProgress(100);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
    l.setTypeface(tf);

    YAxis yl = mChart.getAxisLeft();
    yl.setTypeface(tf);
    yl.setAxisMinValue(0f); // this replaces setStartAtZero(true)
    
    mChart.getAxisRight().setEnabled(false);

    XAxis xl = mChart.getXAxis();
    xl.setTypeface(tf);
    xl.setDrawGridLines(false);
}
 
Example #17
Source File: ScatterChartManager.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
@Override
protected ScatterChart createViewInstance(ThemedReactContext reactContext) {
    return new ScatterChart(reactContext);
}
 
Example #18
Source File: RealmScatterDataSet.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
public ScatterChart.ScatterShape getScatterShape() {
    return mScatterShape;
}
 
Example #19
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 4 votes vote down vote up
public ItemActionOnClickListener(CalibrationLinearityActivity calibrationLinearityActivity, ScatterChart scatterChart) {
    this.calibrationLinearityActivity = calibrationLinearityActivity;
    this.scatterChart = scatterChart;
}
 
Example #20
Source File: IScatterDataSet.java    From Stayfit with Apache License 2.0 2 votes vote down vote up
/**
 * Returns all the different scattershapes the chart uses
 *
 * @return
 */
ScatterChart.ScatterShape getScatterShape();
 
Example #21
Source File: ScatterDataSet.java    From NetKnight with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the shapeIdentifier that this DataSet should be drawn with.
 * Make sure the ScatterChart has a renderer capable of rendering the provided identifier.
 *
 * @param shape
 */
public void setScatterShape(ScatterChart.ScatterShape shape) {
    mScatterShape = shape.toString();
}
 
Example #22
Source File: RealmScatterDataSet.java    From NetKnight with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the shape that is drawn on the position where the values are at.
 *
 * @param shape
 */
public void setScatterShape(ScatterChart.ScatterShape shape) {
    mScatterShape = shape.toString();
}
 
Example #23
Source File: RealmScatterDataSet.java    From Stayfit with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the shape that is drawn on the position where the values are at. If
 * "CUSTOM" is chosen, you need to call setCustomScatterShape(...) and
 * provide a path object that is drawn as the custom scattershape.
 *
 * @param shape
 */
public void setScatterShape(ScatterChart.ScatterShape shape) {
    mScatterShape = shape;
}
 
Example #24
Source File: ScatterDataSet.java    From android-kline with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the ScatterShape this DataSet should be drawn with. This will search for an available IShapeRenderer and set this
 * renderer for the DataSet.
 *
 * @param shape
 */
public void setScatterShape(ScatterChart.ScatterShape shape) {
    mShapeRenderer = getRendererForShape(shape);
}
 
Example #25
Source File: RealmScatterDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the ScatterShape this DataSet should be drawn with. This will search for an available IShapeRenderer and set this
 * renderer for the DataSet.
 *
 * @param shape
 */
public void setScatterShape(ScatterChart.ScatterShape shape) {
    mShapeRenderer = getRendererForShape(shape);
}
 
Example #26
Source File: ScatterDataSet.java    From Ticket-Analysis with MIT License 2 votes vote down vote up
/**
 * Sets the ScatterShape this DataSet should be drawn with. This will search for an available IShapeRenderer and set this
 * renderer for the DataSet.
 *
 * @param shape
 */
public void setScatterShape(ScatterChart.ScatterShape shape) {
    mShapeRenderer = getRendererForShape(shape);
}
 
Example #27
Source File: ScatterDataSet.java    From StockChart-MPAndroidChart with MIT License 2 votes vote down vote up
/**
 * Sets the ScatterShape this DataSet should be drawn with. This will search for an available IShapeRenderer and set this
 * renderer for the DataSet.
 *
 * @param shape
 */
public void setScatterShape(ScatterChart.ScatterShape shape) {
    mShapeRenderer = getRendererForShape(shape);
}