How to give titles on X-Axis and Y-Axis in android graph using achartengine library?

536 views Asked by At

I'm working on an android eclipse project in which I have to show the teachers feedback report in graph, I have made a graph with static values but now I have to give the titles on X-axis and Y-axis. on X-axis there will be Q1,Q2,Q3,Q4 upto Q15 as 15 blocks are already existing in my graph, on Y-axis I have to give a single title as 'Performance' and as I will show Question numbers on X-axis,I have to show values on Y-axis as 1,2,3,4 and 5(the highest value of graph).

Here is the code which I have used to make this graph using achartengine library.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.barchart);
    //define buttons
    btn1=(Button)findViewById(R.id.button5);
    btn2=(Button)findViewById(R.id.button1);
    btn3=(Button)findViewById(R.id.button2);
    btn4=(Button)findViewById(R.id.button3);
    btn5=(Button)findViewById(R.id.button4);
    qdetail=(Button)findViewById(R.id.button6);

    //define TextViews
    tv1=(TextView)findViewById(R.id.TextView04);
    tv2=(TextView)findViewById(R.id.TextView02);
    tv3=(TextView)findViewById(R.id.TextView03);
    tv4=(TextView)findViewById(R.id.TextView01);
    tv5=(TextView)findViewById(R.id.TextView1);


    la = (LinearLayout) findViewById(R.id.lchart);

    //change color
    btn1.setBackgroundColor(Color.BLUE);
    btn2.setBackgroundColor(Color.YELLOW);
    btn3.setBackgroundColor(Color.GREEN);
    btn4.setBackgroundColor(Color.MAGENTA);
    btn5.setBackgroundColor(Color.RED);

    qdetail.setBackgroundColor(Color.CYAN);

    //change text
    tv1.setText("Amir Rashid");
    tv2.setText("Azhar Jamil");
    tv3.setText("Ikram Afzal");
    tv4.setText("Zainab Akbar");
    tv5.setText("Munir Ahmed");
    //
    qdetail.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View arg0) 
        {
            // TODO Auto-generated method stub
            Intent openStartingPoint=new Intent("com.p.evaluate.QUESTION");
            startActivity(openStartingPoint);                           
        }
    });

    int teacher[] = { 1,2,3,4,5 };
    int feedback[] = { 300,200,100,400,500 };
    for(int m=0;m<15;m++)
    {

    for (int j = 0; j < teacher.length; j++) 
    {
        drawchart(1, teacher[j], feedback[j]);
    }
    View view=new View(this);
    view.setLayoutParams(new LinearLayout.LayoutParams(18,0));
    LinearLayout.LayoutParams params=(LinearLayout.LayoutParams)view.getLayoutParams();
    params.setMargins(1,0,0,0);
    view.setLayoutParams(params);
    la.addView(view);

    }

}

private void drawchart(int count, int teacher, int feedback) {
    // TODO Auto-generated method stub
    System.out.println(count + teacher+ feedback);
    if (teacher == 1) {
        teacher = Color.BLUE;
                    }
    if (teacher == 2) {
        teacher = Color.YELLOW;
                    }
    if (teacher == 3) {
        teacher= Color.GREEN;
                    }

    if (teacher == 4) {
        teacher = Color.MAGENTA;
                    }
    if (teacher == 5) {
        teacher= Color.RED;
                    }


    for(int k=1;k<=count;k++)
    {
        View view=new View(this);
        view.setBackgroundColor(teacher);
        view.setLayoutParams(new LinearLayout.LayoutParams(6,feedback));
        LinearLayout.LayoutParams params=(LinearLayout.LayoutParams)view.getLayoutParams();
        params.setMargins(0,0,0,0);
        view.setLayoutParams(params);
        la.addView(view);
        view.setHorizontalScrollBarEnabled(true);
    }
    }


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

0

There are 0 answers