List of usage examples for org.jfree.chart.axis NumberAxis setStandardTickUnits
public void setStandardTickUnits(TickUnitSource source)
From source file:de.tsystems.mms.apm.performancesignature.PerfSigProjectAction.java
private JFreeChart createTestRunChart(final CategoryDataset dataset, final String customName) { String title = "UnitTest overview"; if (StringUtils.isNotBlank(customName)) { title = customName;/*from w w w . j a v a 2 s. co m*/ } final JFreeChart chart = ChartFactory.createBarChart(title, // title "build", // category axis label "num", // value axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); final CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); //domainAxis.setLowerMargin(0.0); //domainAxis.setUpperMargin(0.0); //domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final StackedBarRenderer br = new StackedBarRenderer(); plot.setRenderer(br); br.setSeriesPaint(0, new Color(0xFF, 0x99, 0x99)); // degraded br.setSeriesPaint(1, ColorPalette.RED); // failed br.setSeriesPaint(2, new Color(0x00, 0xFF, 0x00)); // improved br.setSeriesPaint(3, ColorPalette.GREY); // invalidated br.setSeriesPaint(4, ColorPalette.BLUE); // passed br.setSeriesPaint(5, ColorPalette.YELLOW); // volatile return chart; }
From source file:com.rapidminer.gui.plotter.charts.ParetoChartPlotter.java
private JFreeChart createChart() { if (data.getItemCount() > 0) { // get cumulative percentages KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset( "Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(null, // chart title this.dataTable.getColumnName(this.groupByColumn), // domain axis label "Count", // range axis label categoryDataset, // data PlotOrientation.VERTICAL, true, // include legend true, false);//from w ww . j a v a 2s .c o m // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); // get a reference to the plot for further customization... CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); // second data set (cumulative percentages) CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker()); NumberAxis axis2 = new NumberAxis("Percent of " + countValue); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis2.setLabelFont(LABEL_FONT_BOLD); axis2.setTickLabelFont(LABEL_FONT); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); axis2.setTickUnit(new NumberTickUnit(0.1)); // show grid lines plot.setRangeGridlinesVisible(true); // bring cumulative line to front plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); if (isLabelRotating()) { domainAxis.setTickLabelsVisible(true); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } return chart; } else { return null; } }
From source file:edu.ucla.stat.SOCR.chart.SuperPowerChart.java
/** * Creates a chart.//from w w w .ja v a 2s . co m * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title "Y", // x axis label "X", // y axis label dataset, // data PlotOrientation.HORIZONTAL, !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.martus.client.swingui.actions.ActionMenuCharts.java
private void configureBarChartPlot(JFreeChart barChart) { CategoryPlot plot = (CategoryPlot) barChart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); TickUnitSource units = NumberAxis.createIntegerTickUnits(); rangeAxis.setStandardTickUnits(units); CategoryAxis domainAxis = plot.getDomainAxis(); CategoryLabelPositions newPositions = CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0); domainAxis.setCategoryLabelPositions(newPositions); barChart.addSubtitle(new TextTitle(getLocalization().getFieldLabel("ChartSelectedBulletinsDisclaimerBar"), FontHandler.getDefaultFont(), TextTitle.DEFAULT_TEXT_PAINT, RectangleEdge.BOTTOM, TextTitle.DEFAULT_HORIZONTAL_ALIGNMENT, TextTitle.DEFAULT_VERTICAL_ALIGNMENT, TextTitle.DEFAULT_PADDING)); }
From source file:de.tsystems.mms.apm.performancesignature.PerfSigProjectAction.java
private JFreeChart createChart(final JSONObject jsonObject, final CategoryDataset dataset) throws UnsupportedEncodingException { final String measure = jsonObject.getString(Messages.PerfSigProjectAction_ReqParamMeasure()); final String chartDashlet = jsonObject.getString("chartDashlet"); final String testCase = jsonObject.getString("dashboard"); final String customMeasureName = jsonObject.getString("customName"); final String aggregation = jsonObject.getString("aggregation"); String unit = "", color = Messages.PerfSigProjectAction_DefaultColor(); for (DashboardReport dr : getLastDashboardReports()) { if (dr.getName().equals(testCase)) { final Measure m = dr.getMeasure(chartDashlet, measure); if (m != null) { unit = aggregation.equalsIgnoreCase("Count") ? "num" : m.getUnit(); color = URLDecoder.decode(m.getColor(), "UTF-8"); }/*from w w w . j a va2s .c o m*/ break; } } String title = customMeasureName; if (StringUtils.isBlank(customMeasureName)) title = PerfSigUtils.generateTitle(measure, chartDashlet); final JFreeChart chart = ChartFactory.createBarChart(title, // title "build", // category axis label unit, // value axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend false, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); final CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); //domainAxis.setLowerMargin(0.0); //domainAxis.setUpperMargin(0.0); //domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer(); renderer.setSeriesPaint(0, Color.decode(color)); return chart; }
From source file:com.intel.stl.ui.main.view.PacketRateChartRangeUpdater.java
@Override public void updateChartRange(JFreeChart chart, long lower, long upper) { if (lower > upper) { return;/*ww w . j a v a 2 s. c o m*/ } XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis range = (NumberAxis) xyplot.getRangeAxis(); range.setRangeWithMargins(lower, upper); range.setLowerBound(0); // If upper is less than 1000, don't do anything to convert the y-axis // label and // convert the unit tick. TickUnitSource unitSrc = createTickUnits(upper); if (unitSrc != null) { // Change tick values only if upper is above 1000. range.setStandardTickUnits(unitSrc); xyplot.getRenderer().setBaseToolTipGenerator( new PktsRateToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>", Util.getHHMMSS(), new DecimalFormat("#,##0.00" + " " + unitDes))); } else { range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // y-axis label setChartRangeLabel(range); }
From source file:com.intel.stl.ui.main.view.DataRateChartRangeUpdater.java
@Override public void updateChartRange(JFreeChart chart, long lower, long upper) { if (lower > upper) { return;//from w w w . ja va 2 s .c om } XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis range = (NumberAxis) xyplot.getRangeAxis(); range.setRangeWithMargins(lower, upper); range.setLowerBound(0); // If upper is less than 1000, don't do anything to convert the y-axis // label and // convert the unit tick. TickUnitSource unitSrc = createTickUnits(upper); if (unitSrc != null) { // Change tick values only if upper is above 1000. range.setStandardTickUnits(unitSrc); xyplot.getRenderer().setBaseToolTipGenerator( new StandardXYToolTipGenerator("<html><b>{0}</b><br> Time: {1}<br> Data: {2}</html>", Util.getHHMMSS(), new DecimalFormat("#,##0.00" + " " + unitDes)) { private static final long serialVersionUID = 4825888117284967486L; @Override protected Object[] createItemArray(XYDataset dataset, int series, int item) { String nullXString = "null"; String nullYString = "null"; Object[] result = new Object[3]; result[0] = dataset.getSeriesKey(series).toString(); double x = dataset.getXValue(series, item); if (Double.isNaN(x) && dataset.getX(series, item) == null) { result[1] = nullXString; } else { DateFormat xDateFormat = this.getXDateFormat(); if (xDateFormat != null) { result[1] = xDateFormat.format(new Date((long) x)); } else { result[1] = this.getXFormat().format(x); } } double y = dataset.getYValue(series, item); if (Double.isNaN(y) && dataset.getY(series, item) == null) { result[2] = nullYString; } else { DateFormat yDateFormat = this.getYDateFormat(); if (yDateFormat != null) { result[2] = yDateFormat.format(new Date((long) y)); } else { result[2] = this.getYFormat().format(y / tickUnitSize); } } return result; } }); } else { range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } // y-axis label setChartRangeLabel(range); }
From source file:src.gui.LifelinePanel.java
public void refreshLifeline() { //1. get type and context String dtype = diagram.getChildText("type"); String context = diagram.getChildText("context"); //the frame and lifeline nodes Element frame = diagram.getChild("frame"); String durationStr = frame.getChildText("duration"); float lastIntervalDuration = 0; //condition lifeline if (dtype.equals("condition")) { //check if the context is a action if (context.equals("action")) { //get action/operator Element operatorRef = diagram.getChild("action"); Element operator = null; try { XPath path = new JDOMXPath( "elements/classes/class[@id='" + operatorRef.getAttributeValue("class") + "']/operators/operator[@id='" + operatorRef.getAttributeValue("id") + "']"); operator = (Element) path.selectSingleNode(project); } catch (JaxenException e2) { e2.printStackTrace();//from www . java 2 s .c o m } if (operator != null) { //get the object (can be a parametr. literal, or object) Element objRef = lifeline.getChild("object"); Element attrRef = lifeline.getChild("attribute"); //get object class Element objClass = null; try { XPath path = new JDOMXPath( "elements/classes/class[@id='" + objRef.getAttributeValue("class") + "']"); objClass = (Element) path.selectSingleNode(project); } catch (JaxenException e2) { e2.printStackTrace(); } Element attribute = null; try { XPath path = new JDOMXPath( "elements/classes/class[@id='" + attrRef.getAttributeValue("class") + "']/attributes/attribute[@id='" + attrRef.getAttributeValue("id") + "']"); attribute = (Element) path.selectSingleNode(project); } catch (JaxenException e2) { e2.printStackTrace(); } //if (objClass!=null) Element object = null; //check what is this object (parameterof an action, object, literal) if (objRef.getAttributeValue("element").equals("parameter")) { //get parameter in the action try { XPath path = new JDOMXPath( "parameters/parameter[@id='" + objRef.getAttributeValue("id") + "']"); object = (Element) path.selectSingleNode(operator); } catch (JaxenException e2) { e2.printStackTrace(); } } //Boolean attribute if (attribute.getChildText("type").equals("1")) { Element timeIntervals = lifeline.getChild("timeIntervals"); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Boolean"); for (Iterator<Element> it1 = timeIntervals.getChildren().iterator(); it1.hasNext();) { Element timeInterval = it1.next(); boolean insertPoint = true; Element durationConstratint = timeInterval.getChild("durationConstratint"); Element lowerbound = durationConstratint.getChild("lowerbound"); Element upperbound = durationConstratint.getChild("upperbound"); Element value = timeInterval.getChild("value"); //Add for both lower and upper bound //lower bound float lowerTimePoint = 0; try { lowerTimePoint = Float.parseFloat(lowerbound.getAttributeValue("value")); lastIntervalDuration = lowerTimePoint; } catch (Exception e) { insertPoint = false; } //System.out.println(" > point x= "+ Float.toString(lowerTimePoint)+ " , y= "+ lowerbound.getAttributeValue("value")); if (insertPoint) { series.add(lowerTimePoint, (value.getText().equals("false") ? 0 : 1)); } //upper bound float upperTimePoint = 0; try { upperTimePoint = Float.parseFloat(upperbound.getAttributeValue("value")); lastIntervalDuration = upperTimePoint; } catch (Exception e) { insertPoint = false; } //System.out.println(" > point x= "+ Float.toString(upperTimePoint)+ " , y= "+ lowerbound.getAttributeValue("value")); if (insertPoint && upperTimePoint != lowerTimePoint) { series.add(upperTimePoint, (value.getText().equals("false") ? 0 : 1)); } } dataset.addSeries(series); chart.getXYPlot().setDataset(dataset); XYPlot plot = chart.getXYPlot(); //chart = ChartFactory.createXYStepChart(lifelineName, "time", "value", dataset, PlotOrientation.VERTICAL, false, true, false); //chart = ChartFactory.createXYStepChart(attribute.getChildText("name"), "time", "value", dataset, PlotOrientation.VERTICAL, false, true, false); //chart.setBackgroundPaint(Color.WHITE); //XYPlot plot = (XYPlot)chart.getPlot(); NumberAxis domainAxis = new NumberAxis("Time"); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setAutoRangeIncludesZero(false); //set timing ruler if (durationStr.trim().equals("")) { if (lastIntervalDuration > 0) domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional); else domainAxis.setUpperBound(10.0); } else { try { float dur = Float.parseFloat(durationStr); if (dur >= lastIntervalDuration) { domainAxis.setUpperBound(dur + timingRulerAdditional); } else { domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional); } } catch (Exception e) { if (lastIntervalDuration > 0) domainAxis.setUpperBound(lastIntervalDuration + timingRulerAdditional); else domainAxis.setUpperBound(10.0); } } plot.setDomainAxis(domainAxis); } } } //if this is a possible sequence of action being modeled to a condition else if (context.equals("general")) { } } else if (dtype.equals("state")) { } }
From source file:pr.ui.InputForm.java
private void showErrorsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showErrorsBtnActionPerformed DefaultCategoryDataset categorydataset = new DefaultCategoryDataset(); for (int i = 0; i < algorithm.getErrorLog().size(); i++) { categorydataset.addValue(algorithm.getErrorLog().get(i), "Global error", "" + i); }/* ww w . j a va 2 s .com*/ JFreeChart jfreechart = ChartFactory.createLineChart("Error Graph", null, "Error Graph", categorydataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinesVisible(false); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartUtilities.applyCurrentTheme(jfreechart); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setMouseWheelEnabled(true); Utils.showDialoj("Error Graph", chartpanel, this); }