List of usage examples for org.jfree.chart.axis ValueAxis setUpperBound
public void setUpperBound(double max)
From source file:sim.app.antsvoronoi.AntsVoronoiWithUI.java
public JFrame createBarChartFrame() { barChart = new BarChartGenerator(); barChart.setTitle("Number of Food Closest to Each Ant Hill"); barChart.setYAxisLabel("Food Counts"); barChart.setXAxisLabel("Ant Hill"); CategoryPlot plot = barChart.getChart().getCategoryPlot(); ValueAxis axis = plot.getRangeAxis(); axis.setLowerBound(0);//w ww .ja va 2s .c om AntsForageVoronoi af = (AntsForageVoronoi) state; axis.setUpperBound(af.numFood * .75); BarRenderer renderer = new BarRenderer(); renderer = (BarRenderer) plot.getRenderer(); ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER);//, TextAnchor.BOTTOM_CENTER, 0.0); renderer.setPositiveItemLabelPosition(position); renderer.setNegativeItemLabelPosition(position); plot.setRenderer(renderer); barChartFrame = barChart.createFrame(); barChartFrame.setVisible(true); barChartFrame.setTitle("Bar Chart"); return barChartFrame; }
From source file:virgil.meanback.HistoryInfo.java
public void printChart(Stock stock, List<String[]> list, int days) throws Exception { //?/*from ww w. ja va2s. c o m*/ StandardChartTheme standardChartTheme = new StandardChartTheme("CN"); // standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20)); // standardChartTheme.setRegularFont(new Font("", Font.BOLD, 12)); //? standardChartTheme.setLargeFont(new Font("", Font.BOLD, 18)); //? ChartFactory.setChartTheme(standardChartTheme); DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = list.size() - 1; i >= 0; i--) { String[] s = (String[]) list.get(i); dataSet.addValue(Double.parseDouble(s[1]), days + "", s[0]); dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "", s[0]); float sub = Float.parseFloat(s[2]); float error = Float.parseFloat(s[3]); if (sub > error * 2) { dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "??", s[0]); } } //?????Legend //???? //??URL JFreeChart chart = ChartFactory.createLineChart( stock.getName() + "(" + stock.getCode() + ") ", "", "", dataSet, PlotOrientation.VERTICAL, true, true, false); CategoryPlot cp = chart.getCategoryPlot(); cp.setBackgroundPaint(ChartColor.WHITE); // CategoryAxis categoryAxis = cp.getDomainAxis(); // Lable 90 Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 10); categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); categoryAxis.setTickLabelFont(labelFont);//X?? ValueAxis yAxis = cp.getRangeAxis(); yAxis.setAutoRange(true); double[] d = getAxiasThresold(stock, list); yAxis.setLowerBound(d[0] - 0.15); yAxis.setUpperBound(d[1] + 0.15); LineAndShapeRenderer lasp = (LineAndShapeRenderer) cp.getRenderer(); lasp.setBaseFillPaint(ChartColor.RED); lasp.setDrawOutlines(true); lasp.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D)); LineAndShapeRenderer renderer = (LineAndShapeRenderer) cp.getRenderer(1);//? DecimalFormat decimalformat1 = new DecimalFormat("##.##");//??? renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1)); //???? renderer.setItemLabelsVisible(true);// renderer.setBaseItemLabelsVisible(true);// //????? renderer.setShapesFilled(Boolean.TRUE);//?? renderer.setShapesVisible(true);//? ChartFrame chartFrame = new ChartFrame("??", chart, true); //chart?JavaChartFramejavaJframe???? chartFrame.pack(); //?? chartFrame.setVisible(true);//??? }
From source file:org.apache.qpid.disttest.charting.chartbuilder.BaseChartBuilder.java
private void configureYAxisBounds(final ChartingDefinition chartingDefinition, final JFreeChart chart) { if (chart.getPlot() != null && chart.getPlot() instanceof XYPlot) { ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); if (chartingDefinition.getYAxisLowerBound() != null) { rangeAxis.setLowerBound(chartingDefinition.getYAxisLowerBound()); }/*www .ja va 2s . com*/ if (chartingDefinition.getYAxisUpperBound() != null) { rangeAxis.setUpperBound(chartingDefinition.getYAxisUpperBound()); } } }
From source file:org.utgenome.core.cui.DrawHistogram.java
public void execute() throws Exception { InputStream in = null;//ww w . j a v a 2 s . co m if ("-".equals(input)) { _logger.info("reading from STDIN"); in = new StandardInputStream(); } else { _logger.info("reading from " + input); in = new FileInputStream(input); } List<Double> data = new ArrayList<Double>(); BufferedReader dataSetInput = new BufferedReader(new InputStreamReader(in)); int lineCount = 1; try { // read data set boolean cutOffTail = !Double.isNaN(xMax); boolean cutOffHead = !Double.isNaN(xMin); for (String line; (line = dataSetInput.readLine()) != null; lineCount++) { if (lineCount % 100000 == 0) _logger.info(String.format("read %,d data points", lineCount)); if (line.startsWith("#")) continue; double v = Double.parseDouble(line); if (cutOffTail && v > xMax) continue; if (cutOffHead && v < xMin) continue; data.add(v); } double[] value = new double[data.size()]; for (int i = 0; i < data.size(); ++i) { value[i] = data.get(i); } // draw histogram HistogramDataset dataSet = new HistogramDataset(); dataSet.setType(HistogramType.FREQUENCY); dataSet.addSeries("data", value, numBins); JFreeChart chart = ChartFactory.createHistogram(null, null, "Frequency", dataSet, PlotOrientation.VERTICAL, false, false, false); if (title != null) { chart.setTitle(title); } ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); if (cutOffHead) { domainAxis.setLowerBound(xMin); } if (cutOffTail) { domainAxis.setUpperBound(xMax); } if (xLabel != null) { domainAxis.setLabel(xLabel); } if (yLog) { LogarithmicAxis logAxis = new LogarithmicAxis("Frequency"); logAxis.setAllowNegativesFlag(true); logAxis.setAutoRangeIncludesZero(true); chart.getXYPlot().setRangeAxis(logAxis); } if (!Double.isNaN(yMin)) { chart.getXYPlot().getRangeAxis().setLowerBound(yMin); } if (!Double.isNaN(yMax)) { chart.getXYPlot().getRangeAxis().setUpperBound(yMax); } File outputFile = new File(output); _logger.info("output to " + outputFile); ChartUtilities.saveChartAsPNG(outputFile, chart, width, height); } catch (Exception e) { throw new Exception(String.format("error at line %d: %s", lineCount, e)); } }
From source file:net.sf.clichart.chart.AbstractChartBuilder.java
private void setAxisLimits(ValueAxis axis, Integer minimum, Integer maximum, boolean forceRange) { boolean requiresMaximum = maximum != null && (forceRange || maximum < axis.getUpperBound()); if (requiresMaximum) { axis.setUpperBound(maximum); }/*from w ww . j av a 2s. c o m*/ boolean requiresMinimum = minimum != null && (forceRange || minimum > axis.getLowerBound()); if (requiresMinimum) { axis.setLowerBound(minimum); } }
From source file:jenkins.plugins.livingdoc.chart.ProjectSummaryChart.java
private void adjustBound(ValueAxis valueAxis) { // Since we are showing the ItemLabel on top, add a gap to the // upper-bound value to make sure the // ItemLabel is fully visible(did try with ItemLabelPosition without // success!)//from w ww . j av a2s . c om // @todo : need to find a better solution int gap = (int) (20 * upperBoundCount / (double) DEFAULT_CHART_HEIGHT); valueAxis.setUpperBound(upperBoundCount + (gap < 7 ? 7 : gap)); valueAxis.setLowerBound(lowerBoundCount); }
From source file:vteaexploration.plottools.panels.XYChartPanel.java
public void setChartPanelRanges(int axis, double low, double high) { XYPlot plot = (XYPlot) this.chartPanel.getChart().getPlot(); ValueAxis newaxis = new NumberAxis(); newaxis.setLowerBound(low);//w w w. jav a 2 s . c om newaxis.setUpperBound(high); if (axis == XYChartPanel.XAXIS) { plot.setDomainAxis(newaxis); } else if (axis == XYChartPanel.YAXIS) { plot.setRangeAxis(newaxis); } }
From source file:RDGraphGenerator.java
/** * Creates a sample chart.//w w w . j a v a2s . c om * * @param dataset the dataset for the chart. * * @return A sample chart. */ private JFreeChart createDistChart(String riderID) { String riderName = (String) riders.get(riderID); final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Distances", // chart title "Month", // domain axis label mainDist, // range axis label (CategoryDataset) riderDistances.get(riderID), // data PlotOrientation.VERTICAL, // the plot orientation true, // legend true, // tooltips false // urls ); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("0", "G1"); map.mapKeyToGroup("1", "G1"); map.mapKeyToGroup("2", "G1"); map.mapKeyToGroup("3", "G1"); renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.0); Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f, new Color(0x88, 0x88, 0xFF)); renderer.setSeriesPaint(0, p1); Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f, new Color(0x88, 0xFF, 0x88)); renderer.setSeriesPaint(1, p2); Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f, new Color(0xFF, 0x88, 0x88)); renderer.setSeriesPaint(2, p3); Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f, new Color(0xFF, 0xFF, 0x88)); renderer.setSeriesPaint(3, p4); renderer.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(renderer); plot.setFixedLegendItems(createLegendItems()); ValueAxis va = (ValueAxis) plot.getRangeAxis(); ValueAxis ova = null; try { ova = (ValueAxis) va.clone(); } catch (CloneNotSupportedException cnse) { } ova.setLabel(secondaryDist); ova.setLowerBound(va.getLowerBound() * unitConversion); ova.setUpperBound(va.getUpperBound() * unitConversion); plot.setRangeAxis(1, ova); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); CategoryAxis ca = plot.getDomainAxis(); ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); //Make around the chart transparent. chart.setBackgroundPaint(null); return chart; }
From source file:com.google.gwt.benchmarks.viewer.server.ReportImageServer.java
private JFreeChart createChart(String testName, Result result, String title, List<Result> comparativeResults) { // Find the maximum values across both axes for all of the results // (this chart's own results, plus all comparative results). ///*from ww w . j a va2 s .c o m*/ // This is a stop-gap solution that helps us compare different charts for // the same benchmark method (usually with different user agents) until we // get real comparative functionality in version two. double maxTime = 0; for (Result r : comparativeResults) { for (Trial t : r.getTrials()) { maxTime = Math.max(maxTime, t.getRunTimeMillis()); } } // Determine the number of variables in this benchmark method List<Trial> trials = result.getTrials(); Trial firstTrial = new Trial(); int numVariables = 0; if (trials.size() > 0) { firstTrial = trials.get(0); numVariables = firstTrial.getVariables().size(); } // Display the trial data. // // First, pick the domain and series variables for our graph. // Right now we only handle up to two "user" variables. // We set the domain variable to the be the one containing the most unique // values. // This might be easier if the results had meta information telling us // how many total variables there are, what types they are of, etc.... String domainVariable = null; String seriesVariable = null; Map<String, Set<String>> variableValues = null; if (numVariables == 1) { domainVariable = firstTrial.getVariables().keySet().iterator().next(); } else { // TODO(tobyr): Do something smarter, like allow the user to specify which // variables are domain and series, along with the variables which are // held constant. variableValues = new HashMap<String, Set<String>>(); for (int i = 0; i < trials.size(); ++i) { Trial trial = trials.get(i); Map<String, String> variables = trial.getVariables(); for (Map.Entry<String, String> entry : variables.entrySet()) { String variable = entry.getKey(); Set<String> set = variableValues.get(variable); if (set == null) { set = new TreeSet<String>(); variableValues.put(variable, set); } set.add(entry.getValue()); } } TreeMap<Integer, List<String>> numValuesMap = new TreeMap<Integer, List<String>>(); for (Map.Entry<String, Set<String>> entry : variableValues.entrySet()) { Integer numValues = new Integer(entry.getValue().size()); List<String> variables = numValuesMap.get(numValues); if (variables == null) { variables = new ArrayList<String>(); numValuesMap.put(numValues, variables); } variables.add(entry.getKey()); } if (numValuesMap.values().size() > 0) { domainVariable = numValuesMap.get(numValuesMap.lastKey()).get(0); seriesVariable = numValuesMap.get(numValuesMap.firstKey()).get(0); } } String valueTitle = "time (ms)"; // This axis is time across all charts. if (numVariables == 0) { // Show a bar graph, with a single centered simple bar // 0 variables means there is only 1 trial DefaultCategoryDataset data = new DefaultCategoryDataset(); data.addValue(firstTrial.getRunTimeMillis(), "result", "result"); JFreeChart chart = ChartFactory.createBarChart(title, testName, valueTitle, data, PlotOrientation.VERTICAL, false, false, false); CategoryPlot p = chart.getCategoryPlot(); ValueAxis axis = p.getRangeAxis(); axis.setUpperBound(maxTime + maxTime * 0.1); return chart; } else if (numVariables == 1) { // Show a line graph with only 1 series // Or.... choose between a line graph and a bar graph depending upon // whether the type of the domain is numeric. XYSeriesCollection data = new XYSeriesCollection(); XYSeries series = new XYSeries(domainVariable); for (Trial trial : trials) { double time = trial.getRunTimeMillis(); String domainValue = trial.getVariables().get(domainVariable); series.add(Double.parseDouble(domainValue), time); } data.addSeries(series); JFreeChart chart = ChartFactory.createXYLineChart(title, domainVariable, valueTitle, data, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = chart.getXYPlot(); plot.getRangeAxis().setUpperBound(maxTime + maxTime * 0.1); double maxDomainValue = getMaxValue(comparativeResults, domainVariable); plot.getDomainAxis().setUpperBound(maxDomainValue + maxDomainValue * 0.1); return chart; } else if (numVariables == 2) { // Show a line graph with two series XYSeriesCollection data = new XYSeriesCollection(); Set<String> seriesValues = variableValues.get(seriesVariable); for (String seriesValue : seriesValues) { XYSeries series = new XYSeries(seriesValue); for (Trial trial : trials) { Map<String, String> variables = trial.getVariables(); if (variables.get(seriesVariable).equals(seriesValue)) { double time = trial.getRunTimeMillis(); String domainValue = trial.getVariables().get(domainVariable); series.add(Double.parseDouble(domainValue), time); } } data.addSeries(series); } // TODO(tobyr) - Handle graphs above 2 variables JFreeChart chart = ChartFactory.createXYLineChart(title, domainVariable, valueTitle, data, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); plot.getRangeAxis().setUpperBound(maxTime + maxTime * 0.1); double maxDomainValue = getMaxValue(comparativeResults, domainVariable); plot.getDomainAxis().setUpperBound(maxDomainValue + maxDomainValue * 0.1); return chart; } throw new RuntimeException("The ReportImageServer is not yet able to " + "create charts for benchmarks with more than two variables."); // Sample JFreeChart code for creating certain charts: // Leaving this around until we can handle multivariate charts in dimensions // greater than two. // Code for creating a category data set - probably better with a bar chart // instead of line chart /* * DefaultCategoryDataset data = new DefaultCategoryDataset(); String series * = domainVariable; * * for ( Iterator it = trials.iterator(); it.hasNext(); ) { Trial trial = * (Trial) it.next(); double time = trial.getRunTimeMillis(); String * domainValue = (String) trial.getVariables().get( domainVariable ); * data.addValue( time, series, domainValue ); } * * String title = ""; String categoryTitle = domainVariable; PlotOrientation * orientation = PlotOrientation.VERTICAL; * * chart = ChartFactory.createLineChart( title, categoryTitle, valueTitle, * data, orientation, true, true, false ); */ /* * DefaultCategoryDataset data = new DefaultCategoryDataset(); String * series1 = "firefox"; String series2 = "ie"; * * data.addValue( 1.0, series1, "1024"); data.addValue( 2.0, series1, * "2048"); data.addValue( 4.0, series1, "4096"); data.addValue( 8.0, * series1, "8192"); * * data.addValue( 2.0, series2, "1024"); data.addValue( 4.0, series2, * "2048"); data.addValue( 8.0, series2, "4096"); data.addValue( 16.0, * series2,"8192"); * * String title = ""; String categoryTitle = "size"; PlotOrientation * orientation = PlotOrientation.VERTICAL; * * chart = ChartFactory.createLineChart( title, categoryTitle, valueTitle, * data, orientation, true, true, false ); */ }
From source file:imageviewer.tools.HistogramTool.java
public void plot(MouseEvent e) { if (e.getSource() instanceof ImagePanel) { Image image = ((ImagePanel) e.getSource()).getSource(); Histogram h = image.getHistogram(); SimpleHistogramDataset shd = new SimpleHistogramDataset("Voxel distribution"); for (int i = 0, numBands = h.getNumBands(); i < numBands; i++) { int[] binData = h.getBins(i); for (int j = 0; j < binData.length; j++) { SimpleHistogramBin shb = new SimpleHistogramBin(j - 0.5, j + 0.5, true, false); shb.setItemCount(binData[j]); shd.addBin(shb);//from w w w . j av a 2s . c o m } } double[] domainBounds = null, rangeBounds = null; if (chart != null) { ValueAxis va = chart.getXYPlot().getDomainAxis(); domainBounds = new double[] { va.getLowerBound(), va.getUpperBound() }; va = chart.getXYPlot().getRangeAxis(); rangeBounds = new double[] { va.getLowerBound(), va.getUpperBound() }; } chart = ChartFactory.createHistogram(null, "Voxel value", "Count", shd, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(new Color(20, 30, 45)); chart.setAntiAlias(true); ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); domainAxis.setLabelFont(axisFont); domainAxis.setTickLabelFont(tickFont); domainAxis.setAxisLinePaint(Color.white); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); if (domainBounds != null) { domainAxis.setAutoRange(false); domainAxis.setLowerBound(domainBounds[0]); domainAxis.setUpperBound(domainBounds[1]); } else { domainAxis.setLowerBound(0); } ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); rangeAxis.setLabelFont(axisFont); rangeAxis.setTickLabelFont(tickFont); rangeAxis.setAxisLinePaint(Color.white); rangeAxis.setTickLabelPaint(Color.white); rangeAxis.setLabelPaint(Color.white); if (rangeBounds != null) { rangeAxis.setAutoRange(false); rangeAxis.setLowerBound(rangeBounds[0]); rangeAxis.setUpperBound(rangeBounds[1]); } chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(0, 51, 113)); ((XYBarRenderer) chart.getXYPlot().getRenderer()).setDrawBarOutline(false); chart.getXYPlot().setBackgroundAlpha(0.05f); double[] mean = h.getMean(); double[] sd = h.getStandardDeviation(); IntervalMarker im = new IntervalMarker(mean[0] - sd[0] / 2, mean[0] + sd[0] / 2); im.setPaint(new Color(200, 200, 200, 128)); chart.getXYPlot().addDomainMarker(0, im, Layer.BACKGROUND); cp.setChart(chart); } }