问题
I am using MPAndroidChart.
In an application for scatter data I want to have the data points connected by a line and disable the automatic labels that show up when I plot just a few points.
I've listed my code below for reference,
Is this possible? Thanks
public class StaticPlottingFragment extends Fragment {
private static String TAG = "file_plotting_fragment";
private Typeface tf;
private int count = 100;
private LinkedList<DataPoint> mDataPoints;
public static StaticPlottingFragment newInstance() {
return new StaticPlottingFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.plotting_fragment, container, false);
Log.i(TAG, " In OnCreateView inflate");
// ScatterChart is initialized in plotting_fragment.xml
ScatterChart mChart = (ScatterChart) view.findViewById(R.id.scatterChart1);
// obtain legend object
Legend legend = mChart.getLegend();
// turn off legend
legend.setEnabled(false);
mChart.setData(readScatterDataFromFile(1, 10));
mChart.invalidate();
return view;
}
protected ScatterData readScatterDataFromFile(int dataSets,int count) {
ArrayList<String> xvals = new ArrayList<String>();
List<IScatterDataSet> yset = new ArrayList<IScatterDataSet>();
ScatterChart.ScatterShape[] shapes = ScatterChart.getAllPossibleShapes();
DataLab dataLab = DataLab.get(getActivity());
mDataPoints = dataLab.getDataPoints();
for (int i = 0; i < dataSets; i++) {
List<Entry> yentries = new ArrayList<Entry>();
for (int j = 0; j < count; j++) {
DataPoint dataPoint = mDataPoints.get(j);
xvals.add("" + String.valueOf(dataPoint.gettVal()));
yentries.add(new Entry(dataPoint.getxVal(), j));
}
ScatterDataSet ds = new ScatterDataSet(yentries, "label");
ds.setScatterShapeSize(12f);
ds.setColor(getResources().getColor(R.color.blue25));
ds.setScatterShapeSize(9f);
yset.add(ds);
}
ScatterData d2 = new ScatterData(xvals, yset);
// d.setValueTypeface(tf);
return d2;
}
回答1:
Yes, you can use a CombinedChart
to do that.
Use ScatterData
to draw your shapes, and LineData
to connect them with lines.
You can find more on that in the example project on Github.
You can disable drawing the value labels on any data object by calling data.setDrawValues(false)
.
来源:https://stackoverflow.com/questions/35612824/mpandroidchart-scatter-chart-data-point-markers-and-connecting-the-dots