3
的問題是很清楚裏面:關於X的信息/ Y都表現出活性,但不是在一個片段...X和Y標籤不GraphView顯示片段
在活動圖繪製並且顯示關於X和Y的信息以及該文字的標題。
在片段中,只有graphe的表現,沒有關於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標籤都是以白色爲主色調......在第一個佈局,我的背景是黑色的==> OK
在我的片段,背景爲白色==>不能看到X和Y標籤