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

  • Home
  • SEARCH
  • 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 8989029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:09:10+00:00 2026-06-15T22:09:10+00:00

I am new to android. I am creating a bar chart using achartengine. I

  • 0

I am new to android. I am creating a bar chart using achartengine. I am not able to plot the bar chart. Can you please tell me what am I doing wrong here. I have created a database using sqlite data browser and copied the data base into the assets folder of my project.

I had written a code to draw the bar chart with static values and now i modified it to take values from a database.

package flu.solutions.travelsense;


import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer.Orientation;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;  
import android.view.Menu;
public class ChartActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        XYMultipleSeriesRenderer renderer = getBarDemoRenderer();
        setChartSettings(renderer);
        Intent intent = ChartFactory.getBarChartIntent(this, getBarDemoDataset(), renderer, Type.DEFAULT);
        startActivity(intent);
    }

    public Intent createIntent() 

     {

    String[] titles = new String[] { "Top 10 Destinations", " " };
    List<double[]> values = new ArrayList<double[]>();
    values.add(new double[] { 8, 6, 4, 6, 7, 7, 9, 5, 7, 8, 8 });
    values.add(new double[] {});

    int[] colors = new int[] { Color.RED, Color.BLACK};

    XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
    renderer.setOrientation(Orientation.HORIZONTAL);

    setChartSettings(renderer);

    renderer.setXLabels(1);
    renderer.setYLabels(10);

    renderer.addXTextLabel(1, "Bangalore");
    renderer.addXTextLabel(2, "Mysore");
    renderer.addXTextLabel(3, "Chennai");
    renderer.addXTextLabel(4, "Delhi");
    renderer.addXTextLabel(5, "Kolkatta");
    renderer.addXTextLabel(6, "Kashmir");
    renderer.addXTextLabel(7, "Hyderabad");
    renderer.addXTextLabel(8, "Mumbai");
    renderer.addXTextLabel(9, "Kerala");
    renderer.addXTextLabel(10, "Gujarat");

    int length = renderer.getSeriesRendererCount();
    for (int i = 0; i < length; i++) 
    {
      SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
      seriesRenderer.setDisplayChartValues(false);
      }

    return ChartFactory.getBarChartIntent(this, buildBarDataset(titles, values), renderer,Type.DEFAULT);
    }

    public XYMultipleSeriesRenderer getBarDemoRenderer() {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        renderer.setAxisTitleTextSize(16);
        renderer.setChartTitleTextSize(20);
        renderer.setLabelsTextSize(15);
        renderer.setLegendTextSize(15);
        renderer.setMargins(new int[] {20, 30, 15, 0});
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(Color.BLUE);
        renderer.addSeriesRenderer(r);
        r = new SimpleSeriesRenderer();
        r.setColor(Color.GREEN);
        renderer.addSeriesRenderer(r);
        return renderer;
      }

     private XYMultipleSeriesDataset getBarDemoDataset() {
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        final int nr = 10;
        Random r = new Random();
        int SERIES_NR = 2;
        for (int i = 0; i < SERIES_NR; i++) {
          CategorySeries series = new CategorySeries("Demo series " + (i + 1));
          for (int k = 0; k < nr; k++) {
            series.add(100 + r.nextInt() % 100);
          }
          dataset.addSeries(series.toXYSeries());
        }
        return dataset;
      }



    private void setChartSettings(XYMultipleSeriesRenderer renderer) {
        renderer.setChartTitle("Chart demo");
        renderer.setXTitle("x values");
        renderer.setYTitle("y values");
        renderer.setXAxisMin(0);
        renderer.setXAxisMax(5);
        renderer.setYAxisMin(0);
        renderer.setYAxisMax(250);
      }
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_chart, menu);
        return true;
    }
      }
  • 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-15T22:09:11+00:00Added an answer on June 15, 2026 at 10:09 pm

    your createIntent() method doesn’t even look like its been referenced. i believe that the correct OnCreate would be:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        Intent intent = createIntent();
        startActivity(intent);
    
    }
    

    But you should know that you’re eventually going to want to make your graph load as view rather than intent to get the real-time functionality that you wanted.

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

Sidebar

Related Questions

i am creating a new android application.i am using the table layout. I have
I am using the camera by creating an intent: Intent cameraI = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
I am relatively a new Android developer and I am not able to understand
Right now i am creating a barchart in android using AChartEngine.After getting run of
I am creating a new Android app using SyncAdapter to handle db sync. I
I'm new in creating android app using eclipse. I am planning to create an
when i am creating new android project from visual studio 2010 it gives the
I'm pretty new to the Android scene and I'm having troubles creating an UI
I am working on creating an Action Bar like the one from the new
I am using a progress bar in android, so that till my data is

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.