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

added back date X-Axis for Bar charts, requiring a manually-set date formatting pattern

parent f779157d
Branches
No related tags found
No related merge requests found
......@@ -78,6 +78,7 @@ public class BarChart02 implements ExampleChart {
series.setLineColor(SeriesColor.RED);
chart.getStyleManager().setPlotGridLinesVisible(false);
chart.getStyleManager().setBarFilled(false);
chart.getStyleManager().setDatePattern("YYYY");
return chart;
}
......
......@@ -16,6 +16,8 @@
package com.xeiam.xchart.internal.chartpart;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.xeiam.xchart.Series;
......@@ -70,7 +72,18 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
double firstPosition = gridStep / 2.0;
// set up String formatters that may be encountered
NumberFormatter numberFormatter = new NumberFormatter(styleManager);
NumberFormatter numberFormatter = null;
SimpleDateFormat simpleDateformat = null;
if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) {
numberFormatter = new NumberFormatter(styleManager);
}
else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) {
if (styleManager.getDatePattern() == null) {
throw new RuntimeException("You need to set the Date Formatting Pattern!!!");
}
simpleDateformat = new SimpleDateFormat(styleManager.getDatePattern(), styleManager.getLocale());
simpleDateformat.setTimeZone(styleManager.getTimezone());
}
int counter = 0;
......@@ -80,9 +93,13 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
double tickLabelPosition = margin + firstPosition + gridStep * counter++;
tickLocations.add(tickLabelPosition);
}
else {
else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) {
tickLabels.add(numberFormatter.formatNumber(new BigDecimal(category.toString()), minValue, maxValue, axisDirection));
}
else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) {
tickLabels.add(simpleDateformat.format((((Date) category).getTime())));
}
double tickLabelPosition = (int) (margin + firstPosition + gridStep * counter++);
tickLocations.add(tickLabelPosition);
}
......
......@@ -192,7 +192,7 @@ public class AxisTickDateCalculator extends AxisTickCalculator {
SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, styleManager.getLocale());
simpleDateformat.setTimeZone(styleManager.getTimezone());
simpleDateformat.applyPattern(datePattern);
// simpleDateformat.applyPattern(datePattern);
// return simpleDateformat.format(value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment