List of usage examples for org.jfree.chart.axis CategoryAxis CategoryAxis
public CategoryAxis(String label)
From source file:org.moeaframework.analysis.plot.Plot.java
/** * If the chart has not yet been initialized, creates a chart for * categorical data. If the chart is already initialized, checks if the * chart is for categorical data./*from ww w .j a v a 2 s . c om*/ * * @throws FrameworkException if the chart does not support categorical data */ private void createCategoryPlot() { if (chart == null) { CategoryAxis xAxis = new CategoryAxis(""); NumberAxis yAxis = new NumberAxis("Value"); yAxis.setAutoRangeIncludesZero(false); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(); plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); plot.setRenderer(renderer); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartFactory.getChartTheme().apply(chart); } else if (!(chart.getPlot() instanceof CategoryPlot)) { throw new FrameworkException("Can not combine XY plot and categorial plot"); } }
From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java
/** * ??/*from w ww . j a v a 2 s . co m*/ * * @param title * @param titleFont * @param domainAxisLabel * @param rangeAxisLabel * @param data ?? * @param orientation ? * @param legend * @param tooltips ???? * @param urls ??URL * @param urlGenerator * * @return ?? */ public static JFreeChart createStackedBarChart(String title, java.awt.Font titleFont, String domainAxisLabel, String rangeAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel); ValueAxis valueAxis = new NumberAxis(rangeAxisLabel); // create the renderer... StackedBarRenderer renderer = new StackedBarRenderer(); if (tooltips) { // renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { // renderer.setItemURLGenerator(urlGenerator); renderer.setBaseItemURLGenerator(urlGenerator); } CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
From source file:org.drools.planner.benchmark.core.statistic.PlannerStatistic.java
private void writeWinningScoreDifferenceSummaryChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (SolverBenchmark solverBenchmark : plannerBenchmark.getSolverBenchmarkList()) { ScoreDefinition scoreDefinition = solverBenchmark.getSolverConfig().getScoreDirectorFactoryConfig() .buildScoreDefinition(); for (SingleBenchmark singleBenchmark : solverBenchmark.getSingleBenchmarkList()) { if (singleBenchmark.isSuccess()) { Score score = singleBenchmark.getWinningScoreDifference(); Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score); String solverLabel = solverBenchmark.getName(); if (solverBenchmark.isRankingBest()) { solverLabel += " (winner)"; }/*from w w w . ja v a2 s . c om*/ String planningProblemLabel = singleBenchmark.getProblemBenchmark().getName(); dataset.addValue(scoreGraphValue, solverLabel, planningProblemLabel); } } } CategoryAxis xAxis = new CategoryAxis("Data"); xAxis.setCategoryMargin(0.40); NumberAxis yAxis = new NumberAxis("Winning score difference"); BarRenderer renderer = new BarRenderer(); ItemLabelPosition positiveItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(positiveItemLabelPosition); ItemLabelPosition negativeItemLabelPosition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(negativeItemLabelPosition); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart("Winning score difference summary (higher is better)", JFreeChart.DEFAULT_TITLE_FONT, plot, true); BufferedImage chartImage = chart.createBufferedImage(1024, 768); winningScoreDifferenceSummaryFile = new File(plannerBenchmark.getBenchmarkReportDirectory(), "winningScoreDifferenceSummary.png"); OutputStream out = null; try { out = new FileOutputStream(winningScoreDifferenceSummaryFile); ImageIO.write(chartImage, "png", out); } catch (IOException e) { throw new IllegalArgumentException( "Problem writing winningScoreDifferenceSummaryFile: " + winningScoreDifferenceSummaryFile, e); } finally { IOUtils.closeQuietly(out); } }
From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java
/** * @return a graphic showing the number of agents in the evacuated area *///from ww w .jav a 2s. co m private JFreeChart getGraphic(String title, String legend, String modeName, int inputData[]) { /* * Write only the number of defined picture bins to the plot. */ int data[]; if (inputData.length > this.nofPictureBins) { data = Arrays.copyOfRange(inputData, 0, this.nofPictureBins); } else data = inputData; final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries dataSerie = new XYSeries(legend, false, true); for (int i = 0; i < data.length; i++) { double hour = i * this.binSize / 60.0 / 60.0; dataSerie.add(hour, data[i]); } xyData.addSeries(dataSerie); final JFreeChart chart = ChartFactory.createXYStepChart(title + ", " + modeName + ", it." + this.iteration, "time", "# agents", xyData, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); final CategoryAxis axis1 = new CategoryAxis("hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(new NumberAxis("time")); return chart; }
From source file:edu.ucla.stat.SOCR.chart.ChartGenerator.java
private JFreeChart createBoxAndWhiskerChart(String title, String xLabel, String yLabel, BoxAndWhiskerCategoryDataset dataset) { CategoryAxis domainAxis = new CategoryAxis(xLabel); NumberAxis rangeAxis = new NumberAxis(yLabel); // CategoryItemRenderer renderer = new BoxAndWhiskerRenderer(); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(title, plot); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //columnCount -- category count //RowCount -- serie count if (dataset.getColumnCount() * dataset.getRowCount() < 5) { domainAxis.setLowerMargin(0.2);/*w ww. j av a 2s .c o m*/ domainAxis.setUpperMargin(0.2); if (dataset.getColumnCount() == 1) renderer.setItemMargin(0.5); // domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2); /* System.out.println("lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/ } else if (dataset.getColumnCount() * dataset.getRowCount() < 10) { domainAxis.setLowerMargin(domainAxis.getLowerMargin() * 2); domainAxis.setUpperMargin(domainAxis.getUpperMargin() * 2); if (dataset.getColumnCount() == 1) renderer.setItemMargin(renderer.getItemMargin() * 2); else domainAxis.setCategoryMargin(domainAxis.getCategoryMargin() * 2); /*System.out.println("lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin()); */ } return chart; }
From source file:com.tonbeller.jpivot.chart.ChartFactory.java
/** * Creates a stacked vertical bar chart with default settings. * * @param title the chart title.// ww w.jav a 2s .c o m * @param domainAxisLabel the label for the category axis. * @param rangeAxisLabel the label for the value axis. * @param data the dataset for the chart. * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return The chart. */ public static JFreeChart createStackedBarChart(String title, java.awt.Font titleFont, String domainAxisLabel, String rangeAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel); ValueAxis valueAxis = new NumberAxis(rangeAxisLabel); // create the renderer... StackedBarRenderer renderer = new StackedBarRenderer(); if (tooltips) { renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setItemURLGenerator(urlGenerator); } CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo2.java
private static JFreeChart createBarChart(CategoryDataset dataset) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = new BarRenderer(); if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setBaseNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setBasePositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setBaseNegativeItemLabelPosition(position2); }/*from ww w . j av a 2 s . co m*/ if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Bar Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setDrawBarOutline(false); 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); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); categoryAxis .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:org.pentaho.reporting.engine.classic.extensions.legacy.charts.LegacyChartType.java
private JFreeChart createChart(final Expression aExpression) { if (aExpression instanceof BarLineChartExpression) { final CategoryAxis catAxis = new CategoryAxis("Category");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final CategoryPlot plot = new CategoryPlot(createDataset(), catAxis, barsAxis, new BarRenderer()); plot.setRenderer(1, new LineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createDataset()); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); return new JFreeChart("Bar Line Chart", plot); }// w w w . j a va 2 s .c o m if (aExpression instanceof RingChartExpression) { return ChartFactory.createRingChart("Ring Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof AreaChartExpression) { return ChartFactory.createAreaChart("Area Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof BarChartExpression) { return ChartFactory.createBarChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof LineChartExpression) { return ChartFactory.createLineChart("Line Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof MultiPieChartExpression) { return ChartFactory.createMultiplePieChart("Multi Pie Chart", createDataset(), TableOrder.BY_COLUMN, true, false, false);// NON-NLS } if (aExpression instanceof PieChartExpression) { return ChartFactory.createPieChart("Pie Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof WaterfallChartExpressions) { return ChartFactory.createWaterfallChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.HORIZONTAL, true, false, false);// NON-NLS } if (aExpression instanceof BubbleChartExpression) { return ChartFactory.createBubbleChart("Bubble Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ExtendedXYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ScatterPlotChartExpression) { return ChartFactory.createScatterPlot("Scatter Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYAreaLineChartExpression) { final NumberAxis catAxis = new NumberAxis("Range");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final XYPlot plot = new XYPlot(createXYZDataset(), catAxis, barsAxis, new XYAreaRenderer()); plot.setRenderer(1, new XYLineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createXYZDataset()); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); return new JFreeChart("XY Area Line Chart", plot);// NON-NLS } if (aExpression instanceof XYAreaChartExpression) { return ChartFactory.createXYAreaChart("XY Area Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYBarChartExpression) { return XYBarChartExpression.createXYBarChart("XY Bar Chart", "X", false, "Y", createIntervalXYDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof RadarChartExpression) { final SpiderWebPlot plot = new SpiderWebPlot(createDataset()); return new JFreeChart("Radar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } if (aExpression instanceof ThermometerChartExpression) { final DefaultValueDataset dataset = new DefaultValueDataset(new Double(65.0)); final ThermometerPlot plot = new ThermometerPlot(dataset); return new JFreeChart("Thermometer Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } return null; }
From source file:GeMSE.Visualization.BoxAndWhiskerPlot.java
private void Plot() { BoxAndWhiskerCategoryDataset dataset = CreateDataset(); CategoryAxis xAxis = new CategoryAxis("Type"); NumberAxis yAxis = new NumberAxis("Value"); yAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false);// w ww . j a v a 2s .com renderer.setArtifactPaint(Color.BLACK); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setSeriesOutlinePaint(0, Color.BLACK); renderer.setSeriesPaint(0, Color.BLACK); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(new Color(0, 0, 0, 0)); JFreeChart chart = new JFreeChart(null, new Font("Courier New", Font.PLAIN, 10), plot, true); chart.removeLegend(); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(450, 270)); PlotPanel.setViewportView(chartPanel); }
From source file:com.opendoorlogistics.components.gantt.GanttChartComponent.java
@Override public void execute(final ComponentExecutionApi api, int mode, Object configuration, ODLDatastore<? extends ODLTable> ioDs, ODLDatastoreAlterable<? extends ODLTableAlterable> outputDs) { // Get items and sort by resource then date final StringConventions sc = api.getApi().stringConventions(); List<GanttItem> items = GanttItem.beanMapping.getTableMapping(0).readObjectsFromTable(ioDs.getTableAt(0)); // Rounding doubles to longs can create small errors where a start time is 1 millisecond after an end. // Set all start times to be <= end time for (GanttItem item : items) { if (item.getStart() == null || item.getEnd() == null) { throw new RuntimeException("Found Gannt item with null start or end time."); }/* ww w. j a va 2s.c o m*/ if (item.getStart().getValue() > item.getEnd().getValue()) { item.setStart(item.getEnd()); } } Collections.sort(items, new Comparator<GanttItem>() { @Override public int compare(GanttItem o1, GanttItem o2) { int diff = sc.compareStandardised(o1.getResourceId(), o2.getResourceId()); if (diff == 0) { diff = o1.getStart().compareTo(o2.getStart()); } if (diff == 0) { diff = o1.getEnd().compareTo(o2.getEnd()); } if (diff == 0) { diff = sc.compareStandardised(o1.getActivityId(), o2.getActivityId()); } if (diff == 0) { diff = Colours.compare(o1.getColor(), o2.getColor()); } return diff; } }); // Filter any zero duration items Iterator<GanttItem> it = items.iterator(); while (it.hasNext()) { GanttItem item = it.next(); if (item.getStart().compareTo(item.getEnd()) == 0) { it.remove(); } } // Get average colour for each activity type Map<String, CalculateAverageColour> calcColourMap = api.getApi().stringConventions() .createStandardisedMap(); for (GanttItem item : items) { CalculateAverageColour calc = calcColourMap.get(item.getActivityId()); if (calc == null) { calc = new CalculateAverageColour(); calcColourMap.put(item.getActivityId(), calc); } calc.add(item.getColor()); } // Put into colour map Map<String, Color> colourMap = api.getApi().stringConventions().createStandardisedMap(); for (Map.Entry<String, CalculateAverageColour> entry : calcColourMap.entrySet()) { colourMap.put(entry.getKey(), entry.getValue().getAverage()); } // Split items by resource ArrayList<ArrayList<GanttItem>> splitByResource = new ArrayList<>(); ArrayList<GanttItem> current = null; for (GanttItem item : items) { if (current == null || sc.compareStandardised(current.get(0).getResourceId(), item.getResourceId()) != 0) { current = new ArrayList<>(); splitByResource.add(current); } current.add(item); } // put into jfreechart's task data structure TaskSeries ts = new TaskSeries("Resources"); for (ArrayList<GanttItem> resource : splitByResource) { // get earliest and latest time (last time may not be in the last item) ODLTime earliest = resource.get(0).getStart(); ODLTime latest = null; for (GanttItem item : resource) { if (latest == null || latest.compareTo(item.getEnd()) < 0) { latest = item.getEnd(); } } Task task = new Task(resource.get(0).getResourceId(), new Date(earliest.getTotalMilliseconds()), new Date(latest.getTotalMilliseconds())); // add all items as subtasks for (GanttItem item : resource) { task.addSubtask(new MySubtask(item, new Date(item.getStart().getTotalMilliseconds()), new Date(item.getEnd().getTotalMilliseconds()))); } ts.add(task); } TaskSeriesCollection collection = new TaskSeriesCollection(); collection.add(ts); // Create the plot CategoryAxis categoryAxis = new CategoryAxis(null); DateAxis dateAxis = new DateAxis("Time"); CategoryItemRenderer renderer = new MyRenderer(collection, colourMap); final CategoryPlot plot = new CategoryPlot(collection, categoryAxis, dateAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.getDomainAxis().setLabel(null); ((DateAxis) plot.getRangeAxis()).setDateFormatOverride(new DateFormat() { @Override public Date parse(String source, ParsePosition pos) { // TODO Auto-generated method stub return null; } @Override public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { toAppendTo.append(new ODLTime(date.getTime()).toString()); return toAppendTo; } }); // Create the chart and apply the standard theme without shadows to it api.submitControlLauncher(new ControlLauncherCallback() { @Override public void launchControls(ComponentControlLauncherApi launcherApi) { JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); StandardChartTheme theme = new StandardChartTheme("standard theme", false); theme.setBarPainter(new StandardBarPainter()); theme.apply(chart); class MyPanel extends ChartPanel implements Disposable { public MyPanel(JFreeChart chart) { super(chart); } @Override public void dispose() { // TODO Auto-generated method stub } } MyPanel chartPanel = new MyPanel(chart); launcherApi.registerPanel("Resource Gantt", null, chartPanel, true); } }); }