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

fixed error-bar error

parent 2d83266e
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (C) 2013 Xeiam LLC http://xeiam.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.xeiam.xchart.standalone;
import java.awt.Color;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SeriesColor;
import com.xeiam.xchart.SeriesLineStyle;
import com.xeiam.xchart.SeriesMarker;
import com.xeiam.xchart.SwingWrapper;
/**
* @author timmolter
*/
public class ErrorBarTest {
public static void main(String[] args) throws Exception {
// Test code for plotting
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, 50, 50, 50, 50 };
double[] errdata = new double[] { 50, 20, 10, 50, 40, 20, 10 };
double[] yData2 = new double[] { 50, 80, 90, 0, 10, 30, 40 };
double[] yData3 = new double[] { 150, 120, 110, 100, 90, 70, 60 };
Chart mychart = new Chart(900, 700);
mychart.getStyleManager().setYAxisLogarithmic(false); // set log or linear Y axis
mychart.getStyleManager().setYAxisMin(0);
mychart.getStyleManager().setYAxisMax(150);
mychart.getStyleManager().setErrorBarsColor(Color.black);
Series series1 = mychart.addSeries("Error bar test data", xData, yData1, errdata);
Series series2 = mychart.addSeries("Y+error", xData, yData2);
Series series3 = mychart.addSeries("Y-error", xData, yData3);
series1.setLineStyle(SeriesLineStyle.SOLID);
series1.setMarker(SeriesMarker.DIAMOND);
series1.setMarkerColor(Color.MAGENTA);
series2.setLineStyle(SeriesLineStyle.DASH_DASH);
series2.setMarker(SeriesMarker.NONE);
series2.setLineColor(SeriesColor.RED);
series3.setLineStyle(SeriesLineStyle.DASH_DASH);
series3.setMarker(SeriesMarker.NONE);
series3.setLineColor(SeriesColor.RED);
new SwingWrapper(mychart).displayChart();
}
}
......@@ -106,7 +106,6 @@ public class Series {
yMax = yMinMax[1];
// System.out.println(yMin);
// System.out.println(yMax);
}
/**
......
......@@ -125,9 +125,9 @@ public class PlotContentLineChart extends PlotContent {
}
// System.out.println(y);
double eb = 0.0;
BigDecimal eb = BigDecimal.ZERO;
if (errorBars != null) {
eb = ebItr.next().doubleValue();
eb = new BigDecimal(ebItr.next().doubleValue());
}
int xTransform = (int) (xLeftMargin + (x.subtract(xMin).doubleValue() / xMax.subtract(xMin).doubleValue() * xTickSpace));
......@@ -179,11 +179,18 @@ public class PlotContentLineChart extends PlotContent {
if (errorBars != null) {
g.setColor(getChartPainter().getStyleManager().getErrorBarsColor());
g.setStroke(errorBarStroke);
int bottom = (int) (-1 * bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue()));
int top = (int) (bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue()));
g.drawLine(xOffset, yOffset + bottom, xOffset, yOffset + top);
g.drawLine(xOffset - 3, yOffset + bottom, xOffset + 3, yOffset + bottom);
g.drawLine(xOffset - 3, yOffset + top, xOffset + 3, yOffset + top);
BigDecimal topValue = y.add(eb);
int topEBTransform = (int) (bounds.getHeight() - (yTopMargin + topValue.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace));
int topEBOffset = (int) (bounds.getY() + topEBTransform);
BigDecimal bottomValue = y.subtract(eb);
int bottomEBTransform = (int) (bounds.getHeight() - (yTopMargin + bottomValue.subtract(yMin).doubleValue() / yMax.subtract(yMin).doubleValue() * yTickSpace));
int bottomEBOffset = (int) (bounds.getY() + bottomEBTransform);
g.drawLine(xOffset, topEBOffset, xOffset, bottomEBOffset);
g.drawLine(xOffset - 3, bottomEBOffset, xOffset + 3, bottomEBOffset);
g.drawLine(xOffset - 3, topEBOffset, xOffset + 3, topEBOffset);
}
}
......
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