List of usage examples for org.jfree.chart.axis NumberAxis setStandardTickUnits
public void setStandardTickUnits(TickUnitSource source)
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart.java
/** * Creates a chart.//w w w .ja v a 2 s .co m * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart(chartTitle, //"Bar Chart Demo", // chart title domainLabel, //"Category", // domain axis label rangeLabel, //"Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.wsntools.iris.tools.Graph.java
private void setupChartType(JFreeChart chart) { chart.setBackgroundPaint(Color.white); // plot = chart.getCategoryPlot(); plot = chart.getXYPlot();//w w w . ja va 2 s . c o m plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRange(true); domainAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRange(true); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chartPanel.setChart(chart); }
From source file:org.jfree.chart.demo.CompassFormatDemo.java
/** * Creates a sample chart.//from w w w . j av a 2s .c o m * * @return a sample chart. */ private JFreeChart createChart() { final XYDataset direction = createDirectionDataset(600); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); // configure the range axis to display directions... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); final TickUnits units = new TickUnits(); units.add(new NumberTickUnit(180.0, new CompassFormat())); units.add(new NumberTickUnit(90.0, new CompassFormat())); units.add(new NumberTickUnit(45.0, new CompassFormat())); units.add(new NumberTickUnit(22.5, new CompassFormat())); rangeAxis.setStandardTickUnits(units); // add the wind force with a secondary dataset/renderer/axis plot.setRangeAxis(rangeAxis); final XYItemRenderer renderer2 = new XYAreaRenderer(); final ValueAxis axis2 = new NumberAxis("Force"); axis2.setRange(0.0, 12.0); renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128)); plot.setDataset(1, createForceDataset(600)); plot.setRenderer(1, renderer2); plot.setRangeAxis(1, axis2); plot.mapDatasetToRangeAxis(1, 1); return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformationFamilyChart.java
/** * Creates a chart./*from w w w. j ava 2s. co m*/ * * @param dataset the data for the chart. * * @return a chart. */ protected JFreeChart createChart(XYDataset dataset) { chartTitle = "Power Transform Chart"; // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, //"Power Transform Chart", // chart title domainLabel, // x axis label rangeLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, !legendPanelOn, // include legend true, // tooltips false // urls ); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT)); // 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.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // renderer.setSeriesShape(0, java.awt.Shape.round); renderer.setBaseShapesVisible(false); renderer.setBaseShapesFilled(false); renderer.setBaseLinesVisible(true); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); //change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setUpperMargin(0.05); rangeAxis.setLowerMargin(0.05); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setAutoRangeIncludesZero(false); // domainAxis.setTickLabelsVisible(false); // domainAxis.setTickMarksVisible(false); domainAxis.setUpperMargin(0.05); domainAxis.setLowerMargin(0.05); // OPTIONAL CUSTOMISATION COMPLETED. setYSummary(dataset); return chart; }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.BarChartRenderer.java
public void createChart() { CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset(); report = ChartFactory.createBarChart(this.datasetStrategy.getTitle(), this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset, PlotOrientation.HORIZONTAL, true, true, false);//from w w w . j a v a 2s .co m // report.setBackgroundPaint( Color.lightGray ); report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d)); CategoryPlot categoryplot = (CategoryPlot) report.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.lightGray); categoryplot.setDomainGridlinePaint(Color.lightGray); categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); if (datasetStrategy instanceof CoberturaBarChartStrategy || datasetStrategy instanceof CloverBarChartStrategy || datasetStrategy instanceof MultiCloverBarChartStrategy) { numberaxis.setRange(0.0D, BarChartRenderer.NUMBER_AXIS_RANGE); numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance()); } else { numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } numberaxis.setLowerMargin(0.0D); CategoryAxis axis = categoryplot.getDomainAxis(); axis.setLowerMargin(0.02); // two percent axis.setCategoryMargin(0.10); // ten percent axis.setUpperMargin(0.02); // two percent BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer(); barrenderer.setItemMargin(0.10); barrenderer.setDrawBarOutline(false); barrenderer.setBaseItemLabelsVisible(true); if (datasetStrategy instanceof CoberturaBarChartStrategy || datasetStrategy instanceof CloverBarChartStrategy || datasetStrategy instanceof MultiCloverBarChartStrategy) { barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getPercentInstance(Locale.getDefault()))); } else { barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * categorydataset.getRowCount()); if (height > ChartUtils.MINIMUM_HEIGHT) { super.setHeight(height); } else { super.setHeight(ChartUtils.MINIMUM_HEIGHT); } Paint[] paints = this.datasetStrategy.getPaintColor(); for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) { barrenderer.setSeriesPaint(i, paints[i]); } }
From source file:me.childintime.childintime.ui.window.tool.BmiToolDialog.java
/** * Creates a chart.//ww w .j ava 2s . co m * * @param dataset the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset) { // Create the chart final JFreeChart chart = ChartFactory.createXYLineChart("BMI chart", "Age", "Value", dataset, PlotOrientation.VERTICAL, true, true, false); // Set the background color to the LAF's default chart.setBackgroundPaint(new JPanel().getBackground()); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 0; i < 3; i++) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, true); renderer.setSeriesFillPaint(i, Color.RED); } plot.setRenderer(renderer); plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:org.sonar.plugins.buildstability.BuildStabilityChart.java
private void configureRangeAxis(CategoryPlot plot, String valueLabelSuffix, Font font) { NumberAxis numberAxis = new NumberAxis(); numberAxis.setUpperMargin(0.3);//from w w w.j a v a2s. c o m numberAxis.setTickLabelFont(font); numberAxis.setTickLabelPaint(OUTLINE_COLOR); String suffix = ""; if (valueLabelSuffix != null && !"".equals(valueLabelSuffix)) { suffix = new StringBuilder().append("'").append(valueLabelSuffix).append("'").toString(); } numberAxis.setNumberFormatOverride(new DecimalFormat("0" + suffix)); numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setRangeAxis(numberAxis); }
From source file:hudson.tasks.test.AbstractTestResultAction.java
private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) { final String relPath = getRelPath(req); final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title null, // unused "count", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );/* w w w. j a va 2 s . co m*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setAnchor(StandardLegend.SOUTH); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); // plot.setDomainGridlinesVisible(true); // plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); 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()); StackedAreaRenderer ar = new StackedAreaRenderer2() { @Override public String generateURL(CategoryDataset dataset, int row, int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); return relPath + label.getRun().getNumber() + "/testReport/"; } @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column); AbstractTestResultAction a = label.getRun().getAction(AbstractTestResultAction.class); switch (row) { case 0: return String.valueOf(Messages.AbstractTestResultAction_fail(label.getRun().getDisplayName(), a.getFailCount())); case 1: return String.valueOf(Messages.AbstractTestResultAction_skip(label.getRun().getDisplayName(), a.getSkipCount())); default: return String.valueOf(Messages.AbstractTestResultAction_test(label.getRun().getDisplayName(), a.getTotalCount())); } } }; plot.setRenderer(ar); ar.setSeriesPaint(0, ColorPalette.RED); // Failures. ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips. ar.setSeriesPaint(2, ColorPalette.BLUE); // Total. // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }
From source file:userinterface.HealthAnalystRole.ViewReportJPanel.java
private void createChart() { DefaultCategoryDataset healthDataset = new DefaultCategoryDataset(); int selectedRow = tblHealthTable.getSelectedRow(); Device effects = (Device) tblHealthTable.getValueAt(selectedRow, 0); //Device device= device.getEffectsOnBodyList().getEffectsOnBodyList().; for (Device d : organization.getDeviceDirectory().getDeviceList()) { if (d.getEffectsOnBodyList().getEffectsOnBodyList().isEmpty() || d.getEffectsOnBodyList().getEffectsOnBodyList().size() == 1) { JOptionPane.showMessageDialog(this, "No body organs or only one body organ affected found. At least 2 organs effected records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE); return; } else {/*from w w w . j ava2s . c o m*/ Double organ = Double.parseDouble(txtOrgan.getText()); Double value = d.getMaxSAR(); } } //ArrayList<EffectsOnBody> effectsOnBodyList = device.getEffectsOnBodyList().getEffectsOnBodyList(); /*if (effectsOnBodyList.isEmpty() || effectsOnBodyList.size() == 1) { JOptionPane.showMessageDialog(this, "No body organs or only one body organ affected found. At least 2 organs effected records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE); return; }*/ Double organ = Double.parseDouble(txtOrgan.getText()); for (Device device : organization.getDeviceDirectory().getDeviceList()) { for (EffectsOnBody b1 : device.getEffectsOnBodyList().getEffectsOnBodyList()) { Double value = device.getMaxSAR(); //healthDataset.addValue(vitalSign.getHeartRate(),"Most Likely Diseases", device.getMaxSAR()); //vitalSignDataset.addValue(vitalSign.getBloodPressure(),"BP", vitalSign.getTimestamp()); //vitalSignDataset.addValue(vitalSign.getWeight(),"WT", vitalSign.getTimestamp()); } } JFreeChart healthSignChart = ChartFactory.createBarChart3D("Effects On Health Chart", "Time Stamp", "Rate", healthDataset, PlotOrientation.VERTICAL, true, false, false); healthSignChart.setBackgroundPaint(Color.white); CategoryPlot vitalSignChartPlot = healthSignChart.getCategoryPlot(); vitalSignChartPlot.setBackgroundPaint(Color.lightGray); CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis(); vitalSignDomainAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis(); vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartFrame chartFrame = new ChartFrame("Chart", healthSignChart); chartFrame.setVisible(true); chartFrame.setSize(500, 500); }
From source file:org.pentaho.di.ui.spoon.trans.StepPerformanceSnapShotDialog.java
private void updateCanvas() { Rectangle bounds = canvas.getBounds(); if (bounds.width <= 0 || bounds.height <= 0) { return;/*from w ww . java2 s.co m*/ } // The list of snapshots : convert to JFreeChart dataset // DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String[] selectedSteps = stepsList.getSelection(); if (selectedSteps == null || selectedSteps.length == 0) { selectedSteps = new String[] { steps[0], }; // first step stepsList.select(0); } int[] dataIndices = dataList.getSelectionIndices(); if (dataIndices == null || dataIndices.length == 0) { dataIndices = new int[] { DATA_CHOICE_WRITTEN, }; dataList.select(0); } boolean multiStep = stepsList.getSelectionCount() > 1; boolean multiData = dataList.getSelectionCount() > 1; boolean calcMoving = !multiStep && !multiData; // A single metric shown for a single step List<Double> movingList = new ArrayList<Double>(); int movingSize = 10; double movingTotal = 0; int totalTimeInSeconds = 0; for (int t = 0; t < selectedSteps.length; t++) { String stepNameCopy = selectedSteps[t]; List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy); if (snapShotList != null && snapShotList.size() > 1) { totalTimeInSeconds = (int) Math .round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000); for (int i = 0; i < snapShotList.size(); i++) { StepPerformanceSnapShot snapShot = snapShotList.get(i); if (snapShot.getTimeDifference() != 0) { double factor = (double) 1000 / (double) snapShot.getTimeDifference(); for (int d = 0; d < dataIndices.length; d++) { String dataType; if (multiStep) { dataType = stepNameCopy; } else { dataType = dataChoices[dataIndices[d]]; } String xLabel = Integer.toString(Math.round(i * timeDifference / 1000)); Double metric = null; switch (dataIndices[d]) { case DATA_CHOICE_INPUT: metric = snapShot.getLinesInput() * factor; break; case DATA_CHOICE_OUTPUT: metric = snapShot.getLinesOutput() * factor; break; case DATA_CHOICE_READ: metric = snapShot.getLinesRead() * factor; break; case DATA_CHOICE_WRITTEN: metric = snapShot.getLinesWritten() * factor; break; case DATA_CHOICE_UPDATED: metric = snapShot.getLinesUpdated() * factor; break; case DATA_CHOICE_REJECTED: metric = snapShot.getLinesRejected() * factor; break; case DATA_CHOICE_INPUT_BUFFER_SIZE: metric = (double) snapShot.getInputBufferSize(); break; case DATA_CHOICE_OUTPUT_BUFFER_SIZE: metric = (double) snapShot.getOutputBufferSize(); break; default: break; } if (metric != null) { dataset.addValue(metric, dataType, xLabel); if (calcMoving) { movingTotal += metric; movingList.add(metric); if (movingList.size() > movingSize) { movingTotal -= movingList.get(0); movingList.remove(0); } double movingAverage = movingTotal / movingList.size(); dataset.addValue(movingAverage, dataType + "(Avg)", xLabel); // System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m"); } } } } } } } String chartTitle = title; if (multiStep) { chartTitle += " (" + dataChoices[dataIndices[0]] + ")"; } else { chartTitle += " (" + selectedSteps[0] + ")"; } final JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), Long.toString(timeDifference)), // domain axis label BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false); // urls chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setForegroundAlpha(0.5f); plot.setRangeGridlinesVisible(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelsVisible(false); // Customize the renderer... // LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setSeriesStroke(0, new BasicStroke(1.5f)); renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f)); renderer.setSeriesStroke(1, new BasicStroke(2.5f)); renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f)); renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height); ImageData imageData = ImageUtil.convertToSWT(bufferedImage); // dispose previous image... // if (image != null) { image.dispose(); } image = new Image(display, imageData); // Draw the image on the canvas... // canvas.redraw(); }