Skip to content
Snippets Groups Projects
Commit 56e85641 authored by Tim Molter's avatar Tim Molter
Browse files

Fix for x-axis wrong order for bar charts - issue #58

parent dfc2cf9f
No related branches found
No related tags found
No related merge requests found
......@@ -46,8 +46,8 @@ public class BarChart04 implements ExampleChart {
// Create Chart
Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("XFactor vs. Age").xAxisTitle("Age").yAxisTitle("XFactor").build();
chart.addSeries("male", new double[] { 10, 20, 30, 50 }, new double[] { 40, 30, 20, 60 });
chart.addSeries("female", new double[] { 10, 20, 30, 40, 50 }, new double[] { 50, 10, 20, 40, 35 });
chart.addSeries("male", new double[] { 10, 20, 30, 50 }, new double[] { 40, 30, 20, 60 });
chart.getStyleManager().setYAxisMin(5);
chart.getStyleManager().setYAxisMax(70);
......
......@@ -15,10 +15,10 @@
*/
package com.xeiam.xchart.internal.chartpart;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.List;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.internal.Utils;
......@@ -50,13 +50,13 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
private void calculate(ChartPainter chartPainter) {
// tick space - a percentage of the working space available for ticks
int tickSpace = (int)(styleManager.getAxisTickSpaceRatio() * workingSpace); // in plot space
int tickSpace = (int) (styleManager.getAxisTickSpaceRatio() * workingSpace); // in plot space
// where the tick should begin in the working space in pixels
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);
// get all categories
Set<Object> categories = new TreeSet<Object>();
List<Object> categories = new ArrayList<Object>();
for (Series series : chartPainter.getAxisPair().getSeriesMap().values()) {
Iterator<?> xItr = series.getXData().iterator();
......@@ -71,7 +71,9 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.String) {
x = xItr.next();
}
categories.add(x);
if (!categories.contains(x)) {
categories.add(x);
}
}
}
......
......@@ -18,10 +18,10 @@ package com.xeiam.xchart.internal.chartpart;
import java.awt.Graphics2D;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.List;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.StyleManager;
......@@ -47,22 +47,25 @@ public class PlotContentBarChart extends PlotContent {
Rectangle2D bounds = plot.getBounds();
StyleManager styleManager = plot.getChartPainter().getStyleManager();
// X-Axis
int xTickSpace = (int)(styleManager.getAxisTickSpaceRatio() * bounds.getWidth());
int xTickSpace = (int) (styleManager.getAxisTickSpaceRatio() * bounds.getWidth());
int xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace);
// Y-Axis
int yTickSpace = (int)(styleManager.getAxisTickSpaceRatio() * bounds.getHeight());
int yTickSpace = (int) (styleManager.getAxisTickSpaceRatio() * bounds.getHeight());
int yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
// get all categories
Set<Object> categories = new TreeSet<Object>();
List<Object> categories = new ArrayList<Object>();
for (Series series : getChartPainter().getAxisPair().getSeriesMap().values()) {
Iterator<?> xItr = series.getXData().iterator();
while (xItr.hasNext()) {
categories.add(xItr.next());
Object object = xItr.next();
if (!categories.contains(object)) {
categories.add(object);
}
}
}
int numBars = categories.size();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment