MPAndroidChart散点图数据点标记和连接点 [英] MPAndroidChart Scatter Chart data point markers and connecting the dots
问题描述
我正在使用 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,
这可能吗?谢谢
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;
}
推荐答案
是的,您可以使用CombinedChart
来做到这一点.
Yes, you can use a CombinedChart
to do that.
使用ScatterData
绘制形状,并使用LineData
将其与直线连接.
Use ScatterData
to draw your shapes, and LineData
to connect them with lines.
您可以在Github上的示例项目中找到更多信息.
You can find more on that in the example project on Github.
您可以通过调用data.setDrawValues(false)
禁用在任何数据对象上绘制值标签.
You can disable drawing the value labels on any data object by calling data.setDrawValues(false)
.
这篇关于MPAndroidChart散点图数据点标记和连接点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!