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

added ability to format x and y axis independently

parent ee535066
Branches
No related tags found
No related merge requests found
Showing
with 193 additions and 117 deletions
...@@ -33,6 +33,7 @@ import javax.swing.tree.TreeSelectionModel; ...@@ -33,6 +33,7 @@ import javax.swing.tree.TreeSelectionModel;
import com.xeiam.xchart.XChartPanel; import com.xeiam.xchart.XChartPanel;
import com.xeiam.xchart.demo.charts.area.AreaChart01; import com.xeiam.xchart.demo.charts.area.AreaChart01;
import com.xeiam.xchart.demo.charts.area.AreaChart02; import com.xeiam.xchart.demo.charts.area.AreaChart02;
import com.xeiam.xchart.demo.charts.area.AreaLineChart03;
import com.xeiam.xchart.demo.charts.bar.BarChart01; import com.xeiam.xchart.demo.charts.bar.BarChart01;
import com.xeiam.xchart.demo.charts.bar.BarChart02; import com.xeiam.xchart.demo.charts.bar.BarChart02;
import com.xeiam.xchart.demo.charts.bar.BarChart03; import com.xeiam.xchart.demo.charts.bar.BarChart03;
...@@ -47,7 +48,12 @@ import com.xeiam.xchart.demo.charts.date.DateChart04; ...@@ -47,7 +48,12 @@ import com.xeiam.xchart.demo.charts.date.DateChart04;
import com.xeiam.xchart.demo.charts.date.DateChart05; import com.xeiam.xchart.demo.charts.date.DateChart05;
import com.xeiam.xchart.demo.charts.date.DateChart06; import com.xeiam.xchart.demo.charts.date.DateChart06;
import com.xeiam.xchart.demo.charts.date.DateChart07; import com.xeiam.xchart.demo.charts.date.DateChart07;
import com.xeiam.xchart.demo.charts.line.*; import com.xeiam.xchart.demo.charts.line.LineChart01;
import com.xeiam.xchart.demo.charts.line.LineChart02;
import com.xeiam.xchart.demo.charts.line.LineChart03;
import com.xeiam.xchart.demo.charts.line.LineChart04;
import com.xeiam.xchart.demo.charts.line.LineChart05;
import com.xeiam.xchart.demo.charts.line.LineChart06;
import com.xeiam.xchart.demo.charts.realtime.RealtimeChart01; import com.xeiam.xchart.demo.charts.realtime.RealtimeChart01;
import com.xeiam.xchart.demo.charts.realtime.RealtimeChart02; import com.xeiam.xchart.demo.charts.realtime.RealtimeChart02;
import com.xeiam.xchart.demo.charts.scatter.ScatterChart01; import com.xeiam.xchart.demo.charts.scatter.ScatterChart01;
...@@ -189,6 +195,9 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { ...@@ -189,6 +195,9 @@ public class XChartDemo extends JPanel implements TreeSelectionListener {
defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("AreaChart02 - Null Y-Axis Data Points", new AreaChart02().getChart())); defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("AreaChart02 - Null Y-Axis Data Points", new AreaChart02().getChart()));
category.add(defaultMutableTreeNode); category.add(defaultMutableTreeNode);
defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("AreaLineChart03 - Combination Line & Area Chart", new AreaLineChart03().getChart()));
category.add(defaultMutableTreeNode);
// Line category // Line category
category = new DefaultMutableTreeNode("Line Charts"); category = new DefaultMutableTreeNode("Line Charts");
top.add(category); top.add(category);
...@@ -211,9 +220,6 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { ...@@ -211,9 +220,6 @@ public class XChartDemo extends JPanel implements TreeSelectionListener {
defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("LineChart06 - Logarithmic Y-Axis with Error Bars", new LineChart06().getChart())); defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("LineChart06 - Logarithmic Y-Axis with Error Bars", new LineChart06().getChart()));
category.add(defaultMutableTreeNode); category.add(defaultMutableTreeNode);
defaultMutableTreeNode = new DefaultMutableTreeNode(new ChartInfo("LineAreaChart07 - Line & Area Chart", new LineAreaChart07().getChart()));
category.add(defaultMutableTreeNode);
// Scatter category // Scatter category
category = new DefaultMutableTreeNode("Scatter Charts"); category = new DefaultMutableTreeNode("Scatter Charts");
top.add(category); top.add(category);
......
...@@ -44,7 +44,7 @@ public class AreaChart01 implements ExampleChart { ...@@ -44,7 +44,7 @@ public class AreaChart01 implements ExampleChart {
public Chart getChart() { public Chart getChart() {
// Create Chart // Create Chart
Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title("AreaChart01").xAxisTitle("X").yAxisTitle("Y").build(); Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title(getClass().getSimpleName()).xAxisTitle("X").yAxisTitle("Y").build();
chart.addSeries("a", new double[] { 0, 3, 5, 7, 9 }, new double[] { -3, 5, 9, 6, 5 }); chart.addSeries("a", new double[] { 0, 3, 5, 7, 9 }, new double[] { -3, 5, 9, 6, 5 });
chart.addSeries("b", new double[] { 0, 2, 4, 6, 9 }, new double[] { -1, 6, 4, 0, 4 }); chart.addSeries("b", new double[] { 0, 2, 4, 6, 9 }, new double[] { -1, 6, 4, 0, 4 });
chart.addSeries("c", new double[] { 0, 1, 3, 8, 9 }, new double[] { -2, -1, 1, 0, 1 }); chart.addSeries("c", new double[] { 0, 1, 3, 8, 9 }, new double[] { -2, -1, 1, 0, 1 });
......
...@@ -47,7 +47,7 @@ public class AreaChart02 implements ExampleChart { ...@@ -47,7 +47,7 @@ public class AreaChart02 implements ExampleChart {
public Chart getChart() { public Chart getChart() {
// Create Chart // Create Chart
Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title("AreaChart02").xAxisTitle("X").yAxisTitle("Y").build(); Chart chart = new ChartBuilder().chartType(ChartType.Area).width(800).height(600).title(getClass().getSimpleName()).xAxisTitle("X").yAxisTitle("Y").build();
List<Integer> xData = new ArrayList<Integer>(); List<Integer> xData = new ArrayList<Integer>();
List<Integer> yData = new ArrayList<Integer>(); List<Integer> yData = new ArrayList<Integer>();
......
...@@ -13,14 +13,17 @@ ...@@ -13,14 +13,17 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.xeiam.xchart.demo.charts.line; package com.xeiam.xchart.demo.charts.area;
import com.xeiam.xchart.*; import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SeriesMarker;
import com.xeiam.xchart.StyleManager;
import com.xeiam.xchart.StyleManager.ChartType;
import com.xeiam.xchart.StyleManager.LegendPosition; import com.xeiam.xchart.StyleManager.LegendPosition;
import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.demo.charts.ExampleChart; import com.xeiam.xchart.demo.charts.ExampleChart;
import java.awt.*;
/** /**
* Combination Line & Area Chart * Combination Line & Area Chart
* <p/> * <p/>
...@@ -30,11 +33,11 @@ import java.awt.*; ...@@ -30,11 +33,11 @@ import java.awt.*;
* <li>Axis Label Alignment * <li>Axis Label Alignment
* <li>Ensuring a chart axis on a tick * <li>Ensuring a chart axis on a tick
*/ */
public class LineAreaChart07 implements ExampleChart { public class AreaLineChart03 implements ExampleChart {
public static void main(String[] args) { public static void main(String[] args) {
ExampleChart exampleChart = new LineAreaChart07(); ExampleChart exampleChart = new AreaLineChart03();
Chart chart = exampleChart.getChart(); Chart chart = exampleChart.getChart();
new SwingWrapper(chart).displayChart(); new SwingWrapper(chart).displayChart();
} }
...@@ -46,11 +49,13 @@ public class LineAreaChart07 implements ExampleChart { ...@@ -46,11 +49,13 @@ public class LineAreaChart07 implements ExampleChart {
Chart chart = new Chart(800, 600); Chart chart = new Chart(800, 600);
// Customize Chart // Customize Chart
chart.setChartTitle("LineAreaChart07"); chart.setChartTitle(getClass().getSimpleName());
chart.setXAxisTitle("Age"); chart.setXAxisTitle("Age");
chart.setYAxisTitle("Amount"); chart.setYAxisTitle("Amount");
chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW);
chart.getStyleManager().setChartType(ChartType.Line);
// @formatter:off
double[] xAges = new double[]{ double[] xAges = new double[]{
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
...@@ -231,6 +236,7 @@ public class LineAreaChart07 implements ExampleChart { ...@@ -231,6 +236,7 @@ public class LineAreaChart07 implements ExampleChart {
0, 0,
0, 0,
0}; 0};
// @formatter:on
Series seriesLiability = chart.addSeries("Liability", xAges, yLiability); Series seriesLiability = chart.addSeries("Liability", xAges, yLiability);
seriesLiability.setMarker(SeriesMarker.NONE); seriesLiability.setMarker(SeriesMarker.NONE);
...@@ -246,7 +252,7 @@ public class LineAreaChart07 implements ExampleChart { ...@@ -246,7 +252,7 @@ public class LineAreaChart07 implements ExampleChart {
seriesPercentile25th.setMarker(SeriesMarker.NONE); seriesPercentile25th.setMarker(SeriesMarker.NONE);
chart.getStyleManager().setYAxisLabelAlignment(StyleManager.TextAlignment.Right); chart.getStyleManager().setYAxisLabelAlignment(StyleManager.TextAlignment.Right);
chart.getStyleManager().setDecimalPattern("$ #,###.##"); // TODO need a different patter for y and x axis chart.getStyleManager().setYAxisDecimalPattern("$ #,###.##");
chart.getStyleManager().setPlotPadding(0); chart.getStyleManager().setPlotPadding(0);
chart.getStyleManager().setAxisTickSpaceRatio(1); chart.getStyleManager().setAxisTickSpaceRatio(1);
......
...@@ -252,10 +252,12 @@ public class Series { ...@@ -252,10 +252,12 @@ public class Series {
} }
public SeriesType getSeriesType() { public SeriesType getSeriesType() {
return seriesType; return seriesType;
} }
public void setSeriesType(SeriesType seriesType) { public void setSeriesType(SeriesType seriesType) {
this.seriesType = seriesType; this.seriesType = seriesType;
} }
...@@ -315,10 +317,12 @@ public class Series { ...@@ -315,10 +317,12 @@ public class Series {
} }
public Color getFillColor() { public Color getFillColor() {
return fillColor; return fillColor;
} }
public void setFillColor(Color fillColor) { public void setFillColor(Color fillColor) {
this.fillColor = fillColor; this.fillColor = fillColor;
} }
......
...@@ -67,9 +67,7 @@ public class StyleManager { ...@@ -67,9 +67,7 @@ public class StyleManager {
} }
public enum TextAlignment { public enum TextAlignment {
Left, Left, Centre, Right;
Centre,
Right;
} }
/** the default Theme */ /** the default Theme */
...@@ -150,6 +148,8 @@ public class StyleManager { ...@@ -150,6 +148,8 @@ public class StyleManager {
private TimeZone timezone; private TimeZone timezone;
private String datePattern; private String datePattern;
private String decimalPattern; private String decimalPattern;
private String xAxisDecimalPattern;
private String yAxisDecimalPattern;
/** /**
* Constructor * Constructor
...@@ -235,6 +235,8 @@ public class StyleManager { ...@@ -235,6 +235,8 @@ public class StyleManager {
timezone = TimeZone.getDefault(); timezone = TimeZone.getDefault();
datePattern = null; // if not null, this override pattern will be used datePattern = null; // if not null, this override pattern will be used
decimalPattern = null; decimalPattern = null;
xAxisDecimalPattern = null;
yAxisDecimalPattern = null;
} }
/** /**
...@@ -881,22 +883,25 @@ public class StyleManager { ...@@ -881,22 +883,25 @@ public class StyleManager {
} }
public TextAlignment getXAxisLabelAlignment() { public TextAlignment getXAxisLabelAlignment() {
return xAxisLabelAlignment; return xAxisLabelAlignment;
} }
public void setXAxisLabelAlignment(TextAlignment xAxisLabelAlignment) { public void setXAxisLabelAlignment(TextAlignment xAxisLabelAlignment) {
this.xAxisLabelAlignment = xAxisLabelAlignment; this.xAxisLabelAlignment = xAxisLabelAlignment;
} }
public TextAlignment getYAxisLabelAlignment() { public TextAlignment getYAxisLabelAlignment() {
return yAxisLabelAlignment; return yAxisLabelAlignment;
} }
public void setYAxisLabelAlignment(TextAlignment yAxisLabelAlignment) { public void setYAxisLabelAlignment(TextAlignment yAxisLabelAlignment) {
this.yAxisLabelAlignment = yAxisLabelAlignment; this.yAxisLabelAlignment = yAxisLabelAlignment;
} }
// Chart Plot Area /////////////////////////////// // Chart Plot Area ///////////////////////////////
/** /**
...@@ -1132,4 +1137,34 @@ public class StyleManager { ...@@ -1132,4 +1137,34 @@ public class StyleManager {
return decimalPattern; return decimalPattern;
} }
public String getXAxisDecimalPattern() {
return xAxisDecimalPattern;
}
/**
* Set the decimal formatting pattern for the X-Axis
*
* @param xAxisDecimalPattern
*/
public void setXAxisDecimalPattern(String xAxisDecimalPattern) {
this.xAxisDecimalPattern = xAxisDecimalPattern;
}
public String getYAxisDecimalPattern() {
return yAxisDecimalPattern;
}
/**
* Set the decimal formatting pattern for the Y-Axis
*
* @param yAxisDecimalPattern
*/
public void setYAxisDecimalPattern(String yAxisDecimalPattern) {
this.yAxisDecimalPattern = yAxisDecimalPattern;
}
} }
...@@ -15,15 +15,21 @@ ...@@ -15,15 +15,21 @@
*/ */
package com.xeiam.xchart.internal.chartpart; package com.xeiam.xchart.internal.chartpart;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.xeiam.xchart.Series; import com.xeiam.xchart.Series;
import com.xeiam.xchart.StyleManager.ChartType; import com.xeiam.xchart.StyleManager.ChartType;
import com.xeiam.xchart.internal.chartpart.Axis.AxisType; import com.xeiam.xchart.internal.chartpart.Axis.AxisType;
import com.xeiam.xchart.internal.style.SeriesColorMarkerLineStyleCycler; import com.xeiam.xchart.internal.style.SeriesColorMarkerLineStyleCycler;
import java.awt.*;
import java.util.*;
import java.util.List;
/** /**
* @author timmolter * @author timmolter
*/ */
......
...@@ -119,7 +119,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator { ...@@ -119,7 +119,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
for (Object category : categories) { for (Object category : categories) {
if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) {
tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf((Double) category), minValue, maxValue)); tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf((Double) category), minValue, maxValue, axisDirection));
} }
else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) {
long span = (long) Math.abs(maxValue - minValue); // in data space long span = (long) Math.abs(maxValue - minValue); // in data space
...@@ -150,7 +150,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator { ...@@ -150,7 +150,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
for (double tickPosition = firstPosition; tickPosition <= maxValue + 2 * gridStep; tickPosition = tickPosition + gridStep) { for (double tickPosition = firstPosition; tickPosition <= maxValue + 2 * gridStep; tickPosition = tickPosition + gridStep) {
if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) {
tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(tickPosition), minValue, maxValue)); tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(tickPosition), minValue, maxValue, axisDirection));
} }
else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) {
long span = (long) Math.abs(maxValue - minValue); // in data space long span = (long) Math.abs(maxValue - minValue); // in data space
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
*/ */
package com.xeiam.xchart.internal.chartpart; package com.xeiam.xchart.internal.chartpart;
import java.awt.*; import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout; import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
......
...@@ -50,7 +50,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { ...@@ -50,7 +50,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator {
// a check if all axis data are the exact same values // a check if all axis data are the exact same values
if (minValue == maxValue) { if (minValue == maxValue) {
tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue)); tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue, axisDirection));
tickLocations.add(workingSpace / 2.0); tickLocations.add(workingSpace / 2.0);
return; return;
} }
...@@ -113,7 +113,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { ...@@ -113,7 +113,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator {
// only add labels for the decades // only add labels for the decades
if (Math.abs(Math.log10(j) % 1) < 0.00000001) { if (Math.abs(Math.log10(j) % 1) < 0.00000001) {
tickLabels.add(numberFormatter.formatLogNumber(j)); tickLabels.add(numberFormatter.formatLogNumber(j, axisDirection));
} }
else { else {
tickLabels.add(null); tickLabels.add(null);
......
...@@ -51,7 +51,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator { ...@@ -51,7 +51,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
// a check if all axis data are the exact same values // a check if all axis data are the exact same values
if (minValue == maxValue) { if (minValue == maxValue) {
tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue)); tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(maxValue), minValue, maxValue, axisDirection));
tickLocations.add(workingSpace / 2.0); tickLocations.add(workingSpace / 2.0);
return; return;
} }
...@@ -74,7 +74,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator { ...@@ -74,7 +74,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
// generate all tickLabels and tickLocations from the first to last position // generate all tickLabels and tickLocations from the first to last position
for (BigDecimal tickPosition = cleanedFirstPosition; tickPosition.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0; tickPosition = tickPosition.add(cleanedGridStep)) { for (BigDecimal tickPosition = cleanedFirstPosition; tickPosition.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0; tickPosition = tickPosition.add(cleanedGridStep)) {
tickLabels.add(numberFormatter.formatNumber(tickPosition, minValue, maxValue)); tickLabels.add(numberFormatter.formatNumber(tickPosition, minValue, maxValue, axisDirection));
// here we convert tickPosition finally to plot space, i.e. pixels // here we convert tickPosition finally to plot space, i.e. pixels
double tickLabelPosition = margin + ((tickPosition.doubleValue() - minValue) / (maxValue - minValue) * tickSpace); double tickLabelPosition = margin + ((tickPosition.doubleValue() - minValue) / (maxValue - minValue) * tickSpace);
tickLocations.add(tickLabelPosition); tickLocations.add(tickLabelPosition);
......
...@@ -20,6 +20,7 @@ import java.text.DecimalFormat; ...@@ -20,6 +20,7 @@ import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import com.xeiam.xchart.StyleManager; import com.xeiam.xchart.StyleManager;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;
/** /**
* @author timmolter * @author timmolter
...@@ -107,21 +108,31 @@ public class NumberFormatter { ...@@ -107,21 +108,31 @@ public class NumberFormatter {
* Format a number value, if the override patterns are null, it uses defaults * Format a number value, if the override patterns are null, it uses defaults
* *
* @param value * @param value
* @param min
* @param max
* @param axisDirection
* @return * @return
*/ */
public String formatNumber(BigDecimal value, double min, double max) { public String formatNumber(BigDecimal value, double min, double max, Direction axisDirection) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale()); NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale());
String decimalPattern; String decimalPattern;
if (styleManager.getDecimalPattern() == null) { if (axisDirection == Direction.X && styleManager.getXAxisDecimalPattern() != null) {
decimalPattern = getFormatPattern(value, min, max); decimalPattern = styleManager.getXAxisDecimalPattern();
} }
else { else if (axisDirection == Direction.Y && styleManager.getYAxisDecimalPattern() != null) {
decimalPattern = styleManager.getYAxisDecimalPattern();
}
else if (styleManager.getDecimalPattern() != null) {
decimalPattern = styleManager.getDecimalPattern(); decimalPattern = styleManager.getDecimalPattern();
} }
else {
decimalPattern = getFormatPattern(value, min, max);
}
DecimalFormat normalFormat = (DecimalFormat) numberFormat; DecimalFormat normalFormat = (DecimalFormat) numberFormat;
normalFormat.applyPattern(decimalPattern); normalFormat.applyPattern(decimalPattern);
...@@ -135,19 +146,26 @@ public class NumberFormatter { ...@@ -135,19 +146,26 @@ public class NumberFormatter {
* @param value * @param value
* @return * @return
*/ */
public String formatLogNumber(double value) { public String formatLogNumber(double value, Direction axisDirection) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale()); NumberFormat numberFormat = NumberFormat.getNumberInstance(styleManager.getLocale());
String decimalPattern; String decimalPattern;
if (styleManager.getDecimalPattern() == null) { if (axisDirection == Direction.X && styleManager.getXAxisDecimalPattern() != null) {
decimalPattern = "0E0"; decimalPattern = styleManager.getXAxisDecimalPattern();
} }
else { else if (axisDirection == Direction.Y && styleManager.getYAxisDecimalPattern() != null) {
decimalPattern = styleManager.getYAxisDecimalPattern();
}
else if (styleManager.getDecimalPattern() != null) {
decimalPattern = styleManager.getDecimalPattern(); decimalPattern = styleManager.getDecimalPattern();
} }
else {
decimalPattern = "0E0";
}
DecimalFormat normalFormat = (DecimalFormat) numberFormat; DecimalFormat normalFormat = (DecimalFormat) numberFormat;
normalFormat.applyPattern(decimalPattern); normalFormat.applyPattern(decimalPattern);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment