Skip to content
Snippets Groups Projects
Commit 81d6aace authored by timmolter's avatar timmolter
Browse files

decimal and date formatting can be set now

parent f0d56eff
No related branches found
No related tags found
No related merge requests found
...@@ -57,12 +57,13 @@ public class AxisTick implements IChartPart, IHideable { ...@@ -57,12 +57,13 @@ public class AxisTick implements IChartPart, IHideable {
private int workingSpace; private int workingSpace;
/** the normal format for tick labels */ /** the normal format for tick labels */
private Format normalFormat; protected Format normalFormat;
/** the scientific format for tick labels */ /** the scientific format for tick labels */
private Format scientificFormat; protected Format scientificFormat;
private SimpleDateFormat simpleDateformat; /** the format for Date tick labels */
protected SimpleDateFormat simpleDateformat;
/** the bounds */ /** the bounds */
private Rectangle bounds; private Rectangle bounds;
...@@ -81,7 +82,7 @@ public class AxisTick implements IChartPart, IHideable { ...@@ -81,7 +82,7 @@ public class AxisTick implements IChartPart, IHideable {
axisTickLabels = new AxisTickLabels(this); axisTickLabels = new AxisTickLabels(this);
axisTickMarks = new AxisTickMarks(this); axisTickMarks = new AxisTickMarks(this);
normalFormat = new DecimalFormat("#.###########"); normalFormat = new DecimalFormat("#.###");
scientificFormat = new DecimalFormat("0.###E0"); scientificFormat = new DecimalFormat("0.###E0");
simpleDateformat = new SimpleDateFormat("MM-dd"); simpleDateformat = new SimpleDateFormat("MM-dd");
...@@ -243,7 +244,7 @@ public class AxisTick implements IChartPart, IHideable { ...@@ -243,7 +244,7 @@ public class AxisTick implements IChartPart, IHideable {
private String format(BigDecimal value) { private String format(BigDecimal value) {
if (axis.axisType == AxisType.NUMBER) { if (axis.axisType == AxisType.NUMBER) {
if (Math.abs(value.doubleValue()) < 9999 && Math.abs(value.doubleValue()) > .0001 || value.doubleValue() == 0) { if (Math.abs(value.doubleValue()) <= 9999 && Math.abs(value.doubleValue()) > .0001 || value.doubleValue() == 0) {
return normalFormat.format(value.doubleValue()); return normalFormat.format(value.doubleValue());
} else { } else {
return scientificFormat.format(value.doubleValue()); return scientificFormat.format(value.doubleValue());
......
...@@ -19,6 +19,8 @@ import java.awt.Color; ...@@ -19,6 +19,8 @@ import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
...@@ -296,4 +298,31 @@ public class Chart { ...@@ -296,4 +298,31 @@ public class Chart {
this.axisPair.xAxis.axisTick.axisTickLabels.font = font; this.axisPair.xAxis.axisTick.axisTickLabels.font = font;
this.axisPair.yAxis.axisTick.axisTickLabels.font = font; this.axisPair.yAxis.axisTick.axisTickLabels.font = font;
} }
/**
* @param pattern - the pattern describing the date and time format
*/
public void setDateFormatter(String pattern) {
this.axisPair.xAxis.axisTick.simpleDateformat = new SimpleDateFormat(pattern);
}
/**
* @param pattern - the pattern describing the decimal format
*/
public void setDecmialFormatter(String pattern) {
this.axisPair.xAxis.axisTick.normalFormat = new DecimalFormat(pattern);
this.axisPair.yAxis.axisTick.normalFormat = new DecimalFormat(pattern);
}
/**
* @param pattern - the pattern describing the scientific notation format
*/
public void setDecmialScientificFormatter(String pattern) {
this.axisPair.xAxis.axisTick.scientificFormat = new DecimalFormat(pattern);
this.axisPair.yAxis.axisTick.scientificFormat = new DecimalFormat(pattern);
}
} }
...@@ -59,7 +59,6 @@ public class Example9 { ...@@ -59,7 +59,6 @@ public class Example9 {
chart.setChartTitle("Sample Chart with Date X-Axis"); chart.setChartTitle("Sample Chart with Date X-Axis");
chart.setXAxisTitle("X"); chart.setXAxisTitle("X");
chart.setYAxisTitle("Y"); chart.setYAxisTitle("Y");
chart.setXAxisTicksVisible(false);
chart.setChartForegroundColor(ChartColor.getAWTColor(ChartColor.GREY)); chart.setChartForegroundColor(ChartColor.getAWTColor(ChartColor.GREY));
chart.setChartGridLinesColor(new Color(255, 255, 255)); chart.setChartGridLinesColor(new Color(255, 255, 255));
chart.setChartBackgroundColor(Color.WHITE); chart.setChartBackgroundColor(Color.WHITE);
...@@ -71,6 +70,8 @@ public class Example9 { ...@@ -71,6 +70,8 @@ public class Example9 {
chart.setAxisLabelsFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); chart.setAxisLabelsFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18));
chart.setChartTickLabelsFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); chart.setChartTickLabelsFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18));
chart.setChartTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11)); chart.setChartTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11));
chart.setDateFormatter("yyyy-MM-dd");
chart.setDecmialFormatter("#.000");
Series series = chart.addDateSeries("Fake Data", xData, yData); Series series = chart.addDateSeries("Fake Data", xData, yData);
series.setLineColor(SeriesColor.BLUE); series.setLineColor(SeriesColor.BLUE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment