3

The problem is pretty clear: the informations about X/Y are showed in activity but not in a fragment...

In the activity the graph is drawn and information about X and Y and the title of the graphe are showed.

In the fragment, only the graphe is showed, no information about X and Y axis neither the title...

Activity:

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;
  }

}

Fragment:

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);  
}

}

What can be the problem ?

EDIT AND SOLUTION:

Silly mistake: the X and Y label are both in white color... In the first layout, my background was black ==> OK

In my fragment, the background was white ==> can't see X and Y label

user2121458
  • 143
  • 1
  • 4
  • 15

1 Answers1

0

in the first example, your LinearLayout was defined in the layout (likely with fixed with/height parameter). Try to define your LL in the fragment also with fixed width/height values.

appsthatmatter
  • 6,347
  • 3
  • 36
  • 40