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 8141223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:26:03+00:00 2026-06-06T12:26:03+00:00

In my project i have to display the bar chart for 30 days with

  • 0

In my project i have to display the bar chart for 30 days with daily net amount. While view of bar chart activity the X-axis labels were collapsed and all are *shown* without any spacing. While i clicked the zoom buttons that time the views are expanded and we can see the bar with their corresponding x-axis labels. I need to show the bar chart on expanded view on the time of activity started.

Coding for display the Bar Chart:

     XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        renderer.setAxisTitleTextSize(16);
        renderer.setChartTitleTextSize(20);
        renderer.setLabelsTextSize(15);
        renderer. setLegendTextSize(15);
//     renderer.setInScroll(true);
        //renderer.setMargins(new int[]{10,10,10,0});
        int length = colors.length;
        for (int j = 0; j < length; j++) {
          SimpleSeriesRenderer r = new SimpleSeriesRenderer();
          r.setColor(colors[j]);
          renderer.addSeriesRenderer(r);
        }
        if(flag==1)
     renderer.setChartTitle("Monthly Basis");
        if(flag==0)
             renderer.setChartTitle("Weekly Basis");
        if(flag==2)
             renderer.setChartTitle("Yearly Basis");
    renderer.setXTitle("Date");
    renderer.setYTitle("NetAmount");

    renderer.setXAxisMin(0);

    //renderer
    renderer.setYAxisMin(100);
   // renderer.setYAxisMax(35000);
    renderer.setAxesColor(Color.GRAY);
    renderer.setLabelsColor(Color.LTGRAY);
          renderer.setXLabels(0);
          //renderer.setYLabels(31);
            renderer.setDisplayChartValues(true);
            renderer.setXLabelsAlign(Align.LEFT);
            renderer.setYLabelsAlign(Align.RIGHT);
          if(flag==0 || flag==1)
          {
             for(int axis=1;axis<=31;axis++)
            {
                String d;
                d=String.valueOf(axis);
                renderer.addTextLabel(axis,d);

            }
          }
          else
          {
              renderer.setXAxisMin(2005);
              for(int axis=2005;axis<=2011;axis++)
                {
                    String d;
                    d=String.valueOf(axis);
                    renderer.addTextLabel(axis,d);

                }

             // renderer.setXLabels(4);
          }
             //renderer.setPanEnabled(false,false);
             //renderer.setZoomEnabled(false,false);
           // renderer.setPanLimits(new double[] { 0, 32, -10, 40 });
          // renderer.setZoomLimits(new double[] { 0, 32, -10, 40 });
            renderer.setZoomRate(3.0f);
            renderer.setBarSpacing(0.25);
            //renderer.set(new  double[] {0,30,100,35000});
            //Intent in;

            List<double[]> xvalues = new ArrayList<double[]>();

            int count=1,j=0;
           if(flag==0 || flag==1)
           {
            double xdata[]=new double[31];
            while(count<32)
            {

            xdata[j]=count;
            count++;
            j++;

            }
            xvalues.add(xdata);
           }
           if(flag==2)
           {
            double xdata[]=new double[7];
            count=2005;
            while(j<7)
            {

            xdata[j]=count;
            count++;
            j++;

            }
            xvalues.add(xdata);
           }


          //  return ChartFactory.getBarChartIntent(context, buildBarDataset(titles,xvalues,values), renderer,
            //    Type.DEFAULT);
            mchart=ChartFactory.getBarChartView(context,buildBarDataset(titles,xvalues,values), renderer, Type.STACKED);
            //LinearLayout layout = (LinearLayout) findViewById(R.id.chart1);
            layout.addView(mchart);
            mchart.repaint();

            //startActivity(in);

  }


     protected XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> xvalues, List<double[]> values) {
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
     int length = titles.length;
     for (int i = 0; i < length; i++) {
    //CategorySeries series = new CategorySeries(titles[i]);
XYSeries series = new XYSeries(titles[i]);
double[] v = values.get(i);
double[]x=xvalues.get(i);

int seriesLength = v.length;
    for (int k = 0; k < seriesLength; k++) {
if(v[k]==0)
{
v[k]=MathHelper.NULL_VALUE;
}
else
{
     series.add(x[k],v[k]);
}
      //Log.i("Invent","X Axis"+x[k]);
//series.add(xdata[k],v[k]);
     }
     dataset.addSeries(series);
    for (int k = 0; k < seriesLength; k++) {
if(v[k]==MathHelper.NULL_VALUE)
{
v[k]=0;
}
     }
    }
   return dataset;
       }


}
  • 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-06T12:26:05+00:00Added an answer on June 6, 2026 at 12:26 pm


    I’m not 100% sure but here goes a shot.

    First you seems to use a deprecated method addTextLabel when current suggested is addXTextLabel.

    Secondly you set setXLabels(0); with seems odd as you are going to have more then 0 XLabels also unsure how this will work with the depreciated method used.

    Thirdly I think the X value in the addTextLabel are actually, a position not a bar index.

    I’m no expert in neither aChartEngine or have time to test your code just now. I will do some testing later tonight and edit this answer with the result. If no other answer helps you.

    (edit)

    After testing your code I get this result:

    labels after inserting

    This is a problem that is solvable in 3 ways:

    • Reduce the number of labels, e.g. only printing ever other.
    • Use a smaller font size for the labels, I think this will be hard in this case, as I think the readability will suffer greatly.
    • Try to make the axis longer by e.g. removing the labels on the other axis. I guess you want to show labels for the amount there so not useful here.

    I have made a very simple and naive implementation of skipping ever other as I think that is the most useful solution here.

    for(int axis=1;axis<=31;axis++)
    {
      if(axis%2 == 1){
        String d;
        d=String.valueOf(axis);
        renderer.addTextLabel(axis,d);
      }
    }
    

    The result looks like this:

    enter image description here

    Hope this helps!

    (edit again)

    New understanding of the question the above is still correct but here is the answer to the question as I under stand it now.

    To get pan to work you need to have pan enabled (already done in this question) and then set xAxisMax to something less then the length of the dataset. In this example it’s easiest to just set it to e.g. 15f this is done like this:

    renderer.setXAxisMax(15.0f);
    

    Hope this is what you wanted.

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

Sidebar

Related Questions

I have a project where I want to display overlays to locate people on
I have a project in which I need to display multiple UITableView instances inside
We have installed RHQ monitoring system http://rhq-project.org/display/RHQ/Home . From that time our program started
I have project asp.net with namespace test and I'm using resources (files Resource.resx and
I have a project in which I prefer only display full screen mode in
I have a asp.net and c# project. I need to print this string out,
I have been working on a project that requires a bar graph to be
I have made a list based navigation bar for my newest project and I
As a part of my project I have to display animated 3d models in
In one of my project i have used reportviewer control to display reports on

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.