zsmiling / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

TYPE.Stacked mode for bar charts has a bug, It will not render all stacks per bar. #381

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a Stacked-Bar-Chart using the Example(SalesStackedBarChart.java) in 
the demo, by adding 1 more color to the color array, 1 more value to the titles 
array and 1 more array value to the "values" list that.
2. Simply run the code and only 2 bars will show up.
3. Just to check you did everything right, simply change the "Type.STACKED" to 
"Type.DEFAULT", and 3 bars will show up for each data point on the x-axis.

What is the expected output? What do you see instead?
A 3-stack of values per bar should be displayed, but only two are displayed. I 
tested it with more than 3 bars and weird things happen, some stacks per bar 
are missing while they appear in others data points.

Please provide a source code snippet that we can use to replicate the
issue.
//************************************
* Copyright (C) 2009 - 2013 SC 4ViewSoft SRL
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.achartengine.chartdemo.demo.chart;

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

import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint.Align;

/**
 * Sales demo bar chart.
 */
public class SalesStackedBarChart extends AbstractDemoChart {
  /**
   * Returns the chart name.
   * 
   * @return the chart name
   */
  public String getName() {
    return "Sales stacked bar chart";
  }

  /**
   * Returns the chart description.
   * 
   * @return the chart description
   */
  public String getDesc() {
    return "The monthly sales for the last 2 years (stacked bar chart)";
  }

  /**
   * Executes the chart demo.
   * 
   * @param context the context
   * @return the built intent
   */
  public Intent execute(Context context) {
    String[] titles = new String[] { "2008", "2007","2008" };
    List<double[]> values = new ArrayList<double[]>();
    values.add(new double[] { 14230, 12300, 14240, 15244, 15900, 19200, 22030, 21200, 19500, 15500,
        12600, 14000 });
    values.add(new double[] { 5230, 7300, 9240, 10540, 7900, 9200, 12030, 11200, 9500, 10500,
        11600, 13500 });
    values.add(new double[] { 5230, 7300, 9240, 10540, 7900, 9200, 12030, 11200, 9500, 10500,
            11600, 13500 });
    int[] colors = new int[] { Color.BLUE, Color.CYAN, Color.RED };
    XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
    setChartSettings(renderer, "Monthly sales in the last 2 years", "Month", "Units sold", 0.5,
        12.5, 0, 24000, Color.GRAY, Color.LTGRAY);
    renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
    renderer.getSeriesRendererAt(1).setDisplayChartValues(true);
    renderer.setXLabels(12);
    renderer.setYLabels(10);
    renderer.setXLabelsAlign(Align.LEFT);
    renderer.setYLabelsAlign(Align.LEFT);
    renderer.setPanEnabled(true, false);
    // renderer.setZoomEnabled(false);
    renderer.setZoomRate(1.1f);
    renderer.setBarSpacing(0.5f);
    return ChartFactory.getBarChartIntent(context, buildBarDataset(titles, values), renderer,
        Type.DEFAULT);
  }

}

//************************************

What version of the product binary library are you using?
acharengine-1.1.0.jar

Please provide any additional information below.
contact me if you need more information.

Original issue reported on code.google.com by zoalor...@gmail.com on 31 Dec 2013 at 1:43

GoogleCodeExporter commented 9 years ago
I have just added code for a new bar chart type: Type.HEAPED which renders the 
stacked bar charts the way you need.

Original comment by 4viewsoft@gmail.com on 7 Jan 2014 at 10:22