我目前正在为大学阶段开发Android应用程序。 这个应用程序必须绘制一个来自某个压力传感器的数据图,绘制这个图我使用的是Androidplot库。
我正在关注Andrloidplot文档的this示例,以创建动态XYPlot,并在项目依赖项中导入了androidplot-core:1.1.0。
在代码编辑器中,每当我调用getGraphWidget()
,setRangeValueFormat()
并尝试访问XYStepMode
字段时,我都会收到“无法解决....方法”错误。< / p>
我在互联网和Androidplot文档上搜索过这个问题,但我找不到任何有用的东西。 我认为这是由我错过的一些重要信息产生的,但我不知道我忘记了什么。
有人已经解决了这个问题并解决了它吗?
这是我班级的一部分,我发现第一个错误,它在最后一行:
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.androidplot.Plot;
import com.androidplot.util.PixelUtils;
import com.androidplot.xy.XYSeries;
import com.androidplot.xy.*;
import java.text.DecimalFormat;
import java.util.Observable;
import java.util.Observer;
/**
* Created by marco on 07/09/16.
*/
public class GraphicChart extends Fragment {
private XYPlot dynamicPlot;
private MyPlotUpdater plotUpdater;
SampleDynamicXYDatasource data;
private Thread myThread;
public GraphicChart(){}
// redraws a plot whenever an update is received:
private class MyPlotUpdater implements Observer {
Plot plot;
public MyPlotUpdater(Plot plot) {
this.plot = plot;
}
@Override
public void update(Observable o, Object arg) {
plot.redraw();
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.graphic_chart_fragment, container, false);
// get handles to our View defined in layout.xml:
dynamicPlot = (XYPlot)getActivity().findViewById(R.id.dynamic_plot);
plotUpdater = new MyPlotUpdater(dynamicPlot);
// only display whole numbers in domain labels
dynamicPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0")); //FIRST ERROR ON THIS LINE
答案 0 :(得分:5)
最后我已经解决了这个问题,我已经比较了我所链接的网站和gitHub上的网站的来源。
我已做出改变:
行
//仅显示域标签中的整数 dynamicPlot.getGraphWidget()。setDomainValueFormat(new DecimalFormat(&#34; 0&#34;));
现在
// only display whole numbers in domain labels
dynamicPlot.getGraph().getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).
setFormat(new DecimalFormat("0"));
XYStepMode
现在只有StepMode
现在以这种方式调用dynamicPlot.setRangeValueFormat(new DecimalFormat("###.#"));
dynamicPlot.getGraph().getLineLabelStyle(
XYGraphWidget.Edge.LEFT).setFormat(new DecimalFormat("###.#"));