use of com.github.mikephil.charting.interfaces.datasets.IScatterDataSet in project MPAndroidChart by PhilJay.
the class ScatterChartRenderer method drawValues.
@Override
public void drawValues(Canvas c) {
// if values are drawn
if (isDrawingValuesAllowed(mChart)) {
List<IScatterDataSet> dataSets = mChart.getScatterData().getDataSets();
for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) {
IScatterDataSet dataSet = dataSets.get(i);
if (!shouldDrawValues(dataSet))
continue;
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
mXBounds.set(mChart, dataSet);
float[] positions = mChart.getTransformer(dataSet.getAxisDependency()).generateTransformedValuesScatter(dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max);
float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset());
iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x);
iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y);
for (int j = 0; j < positions.length; j += 2) {
if (!mViewPortHandler.isInBoundsRight(positions[j]))
break;
// make sure the lines don't do shitty things outside bounds
if ((!mViewPortHandler.isInBoundsLeft(positions[j]) || !mViewPortHandler.isInBoundsY(positions[j + 1])))
continue;
Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min);
if (dataSet.isDrawValuesEnabled()) {
drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min));
}
if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
Drawable icon = entry.getIcon();
Utils.drawImage(c, icon, (int) (positions[j] + iconsOffset.x), (int) (positions[j + 1] + iconsOffset.y), icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
}
}
MPPointF.recycleInstance(iconsOffset);
}
}
}
use of com.github.mikephil.charting.interfaces.datasets.IScatterDataSet in project MPAndroidChart by PhilJay.
the class RealmDatabaseActivityScatter method setData.
private void setData() {
RealmResults<RealmDemoData> result = mRealm.where(RealmDemoData.class).findAll();
RealmScatterDataSet<RealmDemoData> set = new RealmScatterDataSet<RealmDemoData>(result, "xValue", "yValue");
set.setLabel("Realm ScatterDataSet");
set.setScatterShapeSize(9f);
set.setColor(ColorTemplate.rgb("#CDDC39"));
set.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
// add the dataset
dataSets.add(set);
// create a data object with the dataset list
ScatterData data = new ScatterData(dataSets);
styleData(data);
// set data
mChart.setData(data);
mChart.animateY(1400, Easing.EasingOption.EaseInOutQuart);
}
use of com.github.mikephil.charting.interfaces.datasets.IScatterDataSet in project MPAndroidChart by PhilJay.
the class SimpleFragment method generateScatterData.
protected ScatterData generateScatterData(int dataSets, float range, int count) {
ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes();
for (int i = 0; i < dataSets; i++) {
ArrayList<Entry> entries = new ArrayList<Entry>();
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;
}
use of com.github.mikephil.charting.interfaces.datasets.IScatterDataSet in project MPAndroidChart by PhilJay.
the class ScatterChartActivity method onProgressChanged.
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
tvX.setText("" + (mSeekBarX.getProgress() + 1));
tvY.setText("" + (mSeekBarY.getProgress()));
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
ArrayList<Entry> yVals3 = new ArrayList<Entry>();
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
yVals1.add(new Entry(i, val));
}
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
yVals2.add(new Entry(i + 0.33f, val));
}
for (int i = 0; i < mSeekBarX.getProgress(); i++) {
float val = (float) (Math.random() * mSeekBarY.getProgress()) + 3;
yVals3.add(new Entry(i + 0.66f, val));
}
// create a dataset and give it a type
ScatterDataSet set1 = new ScatterDataSet(yVals1, "DS 1");
set1.setScatterShape(ScatterChart.ScatterShape.SQUARE);
set1.setColor(ColorTemplate.COLORFUL_COLORS[0]);
ScatterDataSet set2 = new ScatterDataSet(yVals2, "DS 2");
set2.setScatterShape(ScatterChart.ScatterShape.CIRCLE);
set2.setScatterShapeHoleColor(ColorTemplate.COLORFUL_COLORS[3]);
set2.setScatterShapeHoleRadius(3f);
set2.setColor(ColorTemplate.COLORFUL_COLORS[1]);
ScatterDataSet set3 = new ScatterDataSet(yVals3, "DS 3");
set3.setShapeRenderer(new CustomScatterShapeRenderer());
set3.setColor(ColorTemplate.COLORFUL_COLORS[2]);
set1.setScatterShapeSize(8f);
set2.setScatterShapeSize(8f);
set3.setScatterShapeSize(8f);
ArrayList<IScatterDataSet> dataSets = new ArrayList<IScatterDataSet>();
// add the datasets
dataSets.add(set1);
dataSets.add(set2);
dataSets.add(set3);
// create a data object with the datasets
ScatterData data = new ScatterData(dataSets);
data.setValueTypeface(mTfLight);
mChart.setData(data);
mChart.invalidate();
}
use of com.github.mikephil.charting.interfaces.datasets.IScatterDataSet in project MPAndroidChart by PhilJay.
the class ScatterChartRenderer method drawHighlighted.
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
ScatterData scatterData = mChart.getScatterData();
for (Highlight high : indices) {
IScatterDataSet set = scatterData.getDataSetByIndex(high.getDataSetIndex());
if (set == null || !set.isHighlightEnabled())
continue;
final Entry e = set.getEntryForXValue(high.getX(), high.getY());
if (!isInBoundsX(e, set))
continue;
MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator.getPhaseY());
high.setDraw((float) pix.x, (float) pix.y);
// draw the lines
drawHighlightLines(c, (float) pix.x, (float) pix.y, set);
}
}
Aggregations