我正在使用MPAndroidChart。
在分散数据的应用程序中,我希望通过一条线连接数据点,并禁用当我绘制几个点时显示的自动标签。
我在下面列出了我的代码供参考,
这可能吗?感谢
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;
}
答案 0 :(得分:2)
是的,您可以使用CombinedChart
来执行此操作。
使用ScatterData
绘制形状,LineData
使用线条连接它们。
您可以在Github上的示例项目中找到更多相关内容。
您可以通过调用data.setDrawValues(false)
来禁用在任何数据对象上绘制值标签。