Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:31:04+00:00 2026-06-07T17:31:04+00:00

I like the achartengine charting library for Android, but I keep getting this problem.

  • 0

I like the achartengine charting library for Android, but I keep getting this problem. I want the activity to redraw a chart for different data sets from my db (going back different amounts of time) on a button click. I have three buttons in the activity along with the chart (below the listview that contains the chart). Everything works except some extra garbage characters are drawn behind a button after it is pressed. It doesn’t happen on the first press of a button, but on the press of a button (doesn’t matter which) the garbage appears.

My Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/chart"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#000000"/>

    <Button
        android:id="@+id/oneMonth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="25dp"
        android:text="@string/OneMonth" />

    <Button
        android:id="@+id/twoMonth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="@string/TwoMonth" />

    <Button
        android:id="@+id/threeMonth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="25dp"
        android:text="@string/ThreeMonth" />

</RelativeLayout>

My activity:

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class Plot extends Activity{

 /** Called when the activity is first created. */
    private XYMultipleSeriesDataset mDataset;
    private XYMultipleSeriesRenderer mRenderer;
    List<double[]> values = new ArrayList<double[]>();
    private GraphicalView mChartView;
    private TimeSeries time_series;
    private final String RANGE = "range";
    LinearLayout layout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.plot);

        layout = (LinearLayout)findViewById(R.id.chart);

        final Button set30 = (Button)findViewById(R.id.oneMonth);
        final Button set60 = (Button)findViewById(R.id.twoMonth);
        final Button set90 = (Button)findViewById(R.id.threeMonth);

        set30.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {

                setUpChart(-30);

            }});

        set60.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {

                setUpChart(-60);

            }});



        set90.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {

                setUpChart(-90);

            }});

        }



    @Override
    protected void onResume() {

        super.onResume();
         setUpChart(-30);
    }

    private void fillData(int x) {
        DataBaseHelper helper = new DataBaseHelper(this.getApplicationContext());
        helper.open(DataBaseHelper.READABLE);

        Cursor cursor = helper.getDaysSoManyDaysInThePast(x);

        if(cursor.getCount() != 0){
            DateFormat formatter ; 
             Date date = null; 
              formatter = new SimpleDateFormat(DataBaseHelper.DATE_FORMAT);
             String s;

             int dateCol = cursor.getColumnIndex("date");
             int caffCol = cursor.getColumnIndex("sum(mgCaffeine)");

            for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){

                s = cursor.getString(dateCol);
                try {
                    date = (Date)formatter.parse(s);

                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }   
                int caff = cursor.getInt(caffCol);
                time_series.add(date, caff);            
            }


        }else{
            Toast.makeText(this, "No data", Toast.LENGTH_SHORT).show();
        }

       helper.close();
    }

        private void setUpChart(int x){

            mDataset = new XYMultipleSeriesDataset();
            mRenderer = new XYMultipleSeriesRenderer();
            mRenderer.setAxisTitleTextSize(16);
            mRenderer.setChartTitleTextSize(20);
            mRenderer.setLabelsTextSize(15);
            mRenderer.setLegendTextSize(20);
            mRenderer.setPointSize(3f);

            XYSeriesRenderer r = new XYSeriesRenderer();
            r.setColor(Color.GREEN);
            r.setPointStyle(PointStyle.CIRCLE);
            r.setFillPoints(true);
            mRenderer.addSeriesRenderer(r);
            mRenderer.setClickEnabled(true);
            mRenderer.setSelectableBuffer(20);
            mRenderer.setPanEnabled(true);

            time_series = new TimeSeries("test");
            mDataset.addSeries(time_series);

            fillData(x);

            mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer,
                DataBaseHelper.DATE_FORMAT);



        layout.removeAllViews();
        layout.addView(mChartView);

    }
}

Here’s a picture The garbage is behind the bottom part of the button. Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:31:07+00:00Added an answer on June 7, 2026 at 5:31 pm

    I found a way to fix it — enclose the buttons in a relativelayout and give the linealayout that has the chart a bottom margin of 50dp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem. I'm making a graph with AChartEngine and I would like
Is there android chart library available by which I can easily draw bar char,
I am working on Pie charts using AChartEngine library. Here I want to disable
Like setFont(QFont(Helvetica,16,1)) ,I want to summerize these fonts.However,I dont't know how many fonts there
Like a person asked here (but his solutions as to call a nother function)
Like this one? http://weblogs.asp.net/dwahlin/archive/2007/09/09/c-3-0-features-object-initializers.aspx Person p = new Person() { FirstName = John, LastName
Like the question says is there a better way to write this: SELECT clients_lists.*,
Like in the title I want to swap the field that is rendered on
I have an issue with an achartengine graph - as in this screenshot: It
Like this:(with left click or shortcut) and that would open main.xml It would really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.