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

fixed error bar on log charts

parent 59b12be8
Branches
No related tags found
No related merge requests found
...@@ -39,13 +39,15 @@ public class ErrorBarText2 { ...@@ -39,13 +39,15 @@ public class ErrorBarText2 {
double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
double[] yData1 = new double[] { 100, 100, 100, 10, 10, 10, 10 }; // double[] yData1 = new double[] { 100, 100, 100, 10, 10, 10, 10 };
double[] yData1 = new double[] { 100, 100, 100, 60, 10, 10, 10 };
double[] yData2 = new double[] { 50, 80, 90, 1, 5, 8, 9 }; double[] yData2 = new double[] { 150, 120, 110, 112, 19, 12, 11 };
double[] yData3 = new double[] { 150, 120, 110, 19, 15, 12, 11 }; double[] yData3 = new double[] { 50, 80, 90, 8, 1, 8, 9 };
double[] errdata = new double[] { 1, .699, .301, 2, 1, .699, 0.301 }; // double[] errdata = new double[] { 1, .699, .301, 2, 1, .699, 0.301 };
double[] errdata = new double[] { 50, 20, 10, 52, 9, 2, 1 };
Chart mychart = new Chart(1200, 800); Chart mychart = new Chart(1200, 800);
...@@ -55,10 +57,6 @@ public class ErrorBarText2 { ...@@ -55,10 +57,6 @@ public class ErrorBarText2 {
mychart.getStyleManager().setYAxisMax(1000); mychart.getStyleManager().setYAxisMax(1000);
mychart.getStyleManager().setXAxisMin(0);
mychart.getStyleManager().setXAxisMax(10);
mychart.getStyleManager().setErrorBarsColor(Color.black); mychart.getStyleManager().setErrorBarsColor(Color.black);
Series series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata); Series series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata);
......
...@@ -86,7 +86,8 @@ public class ChartPainter { ...@@ -86,7 +86,8 @@ public class ChartPainter {
throw new IllegalArgumentException("Series data cannot be less or equal to zero for a logarithmic X-Axis!!!"); throw new IllegalArgumentException("Series data cannot be less or equal to zero for a logarithmic X-Axis!!!");
} }
if (getStyleManager().isYAxisLogarithmic() && axisPair.getyAxis().getMin().compareTo(BigDecimal.ZERO) <= 0) { if (getStyleManager().isYAxisLogarithmic() && axisPair.getyAxis().getMin().compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Series data cannot be less or equal to zero for a logarithmic Y-Axis!!!"); System.out.println(axisPair.getyAxis().getMin());
// throw new IllegalArgumentException("Series data cannot be less or equal to zero for a logarithmic Y-Axis!!!");
} }
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint
......
...@@ -118,18 +118,17 @@ public class PlotContentLineChart extends PlotContent { ...@@ -118,18 +118,17 @@ public class PlotContentLineChart extends PlotContent {
x = new BigDecimal(Math.log10(x.doubleValue())); x = new BigDecimal(Math.log10(x.doubleValue()));
} }
BigDecimal y = new BigDecimal(yItr.next().doubleValue()); BigDecimal yOrig = new BigDecimal(yItr.next().doubleValue());
BigDecimal y = null;
if (getChartPainter().getStyleManager().isYAxisLogarithmic()) {
y = new BigDecimal(Math.log10(y.doubleValue()));
}
// System.out.println(y);
BigDecimal eb = BigDecimal.ZERO; BigDecimal eb = BigDecimal.ZERO;
if (errorBars != null) { if (errorBars != null) {
eb = new BigDecimal(ebItr.next().doubleValue()); eb = new BigDecimal(ebItr.next().doubleValue());
} }
// System.out.println(y);
y = new BigDecimal(Math.log10(yOrig.doubleValue()));
int xTransform = (int) (xLeftMargin + (x.subtract(xMin).doubleValue() / xMax.subtract(xMin).doubleValue() * xTickSpace)); int xTransform = (int) (xLeftMargin + (x.subtract(xMin).doubleValue() / xMax.subtract(xMin).doubleValue() * xTickSpace));
int yTransform = (int) (bounds.getHeight() - (yTopMargin + y.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace)); int yTransform = (int) (bounds.getHeight() - (yTopMargin + y.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace));
...@@ -177,14 +176,28 @@ public class PlotContentLineChart extends PlotContent { ...@@ -177,14 +176,28 @@ public class PlotContentLineChart extends PlotContent {
// paint errorbar // paint errorbar
if (errorBars != null) { if (errorBars != null) {
g.setColor(getChartPainter().getStyleManager().getErrorBarsColor()); g.setColor(getChartPainter().getStyleManager().getErrorBarsColor());
g.setStroke(errorBarStroke); g.setStroke(errorBarStroke);
BigDecimal topValue = y.add(eb); BigDecimal topValue = null;
if (getChartPainter().getStyleManager().isYAxisLogarithmic()) {
topValue = yOrig.add(eb);
topValue = new BigDecimal(Math.log10(topValue.doubleValue()));
} else {
topValue = y.add(eb);
}
int topEBTransform = (int) (bounds.getHeight() - (yTopMargin + topValue.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace)); int topEBTransform = (int) (bounds.getHeight() - (yTopMargin + topValue.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace));
int topEBOffset = (int) (bounds.getY() + topEBTransform); int topEBOffset = (int) (bounds.getY() + topEBTransform);
BigDecimal bottomValue = y.subtract(eb); BigDecimal bottomValue = null;
if (getChartPainter().getStyleManager().isYAxisLogarithmic()) {
bottomValue = yOrig.subtract(eb);
System.out.println(bottomValue);
bottomValue = new BigDecimal(Math.log10(bottomValue.doubleValue()));
} else {
bottomValue = y.subtract(eb);
}
int bottomEBTransform = (int) (bounds.getHeight() - (yTopMargin + bottomValue.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace)); int bottomEBTransform = (int) (bounds.getHeight() - (yTopMargin + bottomValue.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace));
int bottomEBOffset = (int) (bounds.getY() + bottomEBTransform); int bottomEBOffset = (int) (bounds.getY() + bottomEBTransform);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment