问题很清楚:关于 X/Y 的信息显示在活动中,而不是在片段中......
在活动中,绘制图形并显示有关 X 和 Y 的信息以及图形的标题。
在片段中,只显示了图形,没有关于 X 和 Y 轴的信息,也没有标题......
活动:
public class Chart extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chart);
//UNDER CONSTRUCTION
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, 1.5d)
, new GraphViewData(3, 2.5d)
, new GraphViewData(4, 1.0d)
});
GraphView graphView = new BarGraphView(
this // context
, "GraphViewDemo" // heading
);
graphView.addSeries(exampleSeries); // data
graphView.setBackgroundColor(Color.BLACK);
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
layout.addView(graphView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
分段:
public class ChartFragment extends Fragment {
GraphView graphView;
LinearLayout layout;
// Parameterless constructor is needed by framework
public ChartFragment() {
super();
}
/**
* Sets up the UI. It consists if a single WebView.
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
layout = new LinearLayout(getActivity());
return layout;
}
public void displayChart(int mCatIndex, int mPeriodIndex) {
int num = 150;
GraphViewData[] data = new GraphViewData[num];
double v=0;
for (int i=0; i<num; i++) {
v += 0.2;
data[i] = new GraphViewData(i, Math.sin(v));
}
graphView = new LineGraphView(
null
, "GraphViewDemo"
);
// add data
graphView.addSeries(new GraphViewSeries(data));
// set view port, start=2, size=40
graphView.setViewPort(2, 40);
graphView.setScrollable(true);
// optional - activate scaling / zooming
graphView.setScalable(true);
layout.addView(graphView);
}
}
可能是什么问题?
编辑和解决方案:
愚蠢的错误:X 和 Y 标签都是白色的......在第一个布局中,我的背景是黑色 ==> 好的
在我的片段中,背景是白色 ==> 看不到 X 和 Y 标签