List of usage examples for org.jfree.chart.plot CategoryPlot setDomainAxis
public void setDomainAxis(CategoryAxis axis)
From source file:org.jfree.chart.demo.StackedBarChartDemo5.java
private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart jfreechart = ChartFactory.createStackedBarChart("Stacked Bar Chart Demo 5", "Category", "Value", categorydataset, PlotOrientation.VERTICAL, true, true, false); GroupedStackedBarRenderer groupedstackedbarrenderer = new GroupedStackedBarRenderer(); KeyToGroupMap keytogroupmap = new KeyToGroupMap("G1"); keytogroupmap.mapKeyToGroup("S1", "G1"); keytogroupmap.mapKeyToGroup("S2", "G1"); keytogroupmap.mapKeyToGroup("S3", "G2"); keytogroupmap.mapKeyToGroup("S4", "G3"); groupedstackedbarrenderer.setSeriesToGroupMap(keytogroupmap); groupedstackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); groupedstackedbarrenderer.setBaseItemLabelsVisible(true); groupedstackedbarrenderer.setPositiveItemLabelPositionFallback( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER)); groupedstackedbarrenderer.setItemMargin(0.10000000000000001D); SubCategoryAxis subcategoryaxis = new SubCategoryAxis("Category / Group"); subcategoryaxis.setCategoryMargin(0.050000000000000003D); subcategoryaxis.addSubCategory("G1"); subcategoryaxis.addSubCategory("G2"); subcategoryaxis.addSubCategory("G3"); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setDomainAxis(subcategoryaxis); categoryplot.setRenderer(groupedstackedbarrenderer); return jfreechart; }
From source file:userinterface.CyberSecurity.ChartFactory.java
public static ChartPanel createChart(UserAccount account) { Map<String, LoginDetails> loginDetails = account.getLoginDetails(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); Collection<LoginDetails> values = loginDetails.values(); for (LoginDetails details : values) { dataset1.addValue(TimeUnit.MILLISECONDS.toHours(details.getLogoutTime() - details.getLoginTime()), HOURS_WORKED_BY_USER, details.getLoginDate()); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, details.getLoginDate()); }/* www. ja v a2 s. c om*/ dataset1.addValue(2, HOURS_WORKED_BY_USER, "4-19-2016"); dataset1.addValue(3, HOURS_WORKED_BY_USER, "4-20-2016"); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-19-2016"); dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-20-2016"); final CategoryItemRenderer renderer = new BarRenderer(); final CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset1); plot.setRenderer(renderer); plot.setDomainAxis(new CategoryAxis("Date")); plot.setRangeAxis(new NumberAxis("Hours")); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); // now create the second dataset and renderer... final CategoryItemRenderer renderer2 = new LineAndShapeRenderer(); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); final JFreeChart chart = new JFreeChart(plot); chart.setTitle("Employee work hours"); chart.setBackgroundPaint(Color.WHITE); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); return chartPanel; }
From source file:org.jfree.chart.demo.SubCategoryAxisDemo1.java
private static JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("SubCategoryAxis Demo 1", "Category", "Value", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); SubCategoryAxis subCategoryAxis = new SubCategoryAxis(null); subCategoryAxis.addSubCategory("S1"); subCategoryAxis.addSubCategory("S2"); subCategoryAxis.addSubCategory("S3"); plot.setDomainAxis(subCategoryAxis); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false);/*from w w w . j av a 2 s .c o m*/ GradientPaint gradientpaint0 = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0, 0, 64)); GradientPaint gradientpaint1 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0, 64, 0)); GradientPaint gradientpaint2 = new GradientPaint(0.0F, 0.0F, Color.red, 0.0F, 0.0F, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gradientpaint0); renderer.setSeriesPaint(1, gradientpaint1); renderer.setSeriesPaint(2, gradientpaint2); return chart; }
From source file:org.jfree.chart.demo.OverlaidBarChartDemo1.java
public static JFreeChart createChart() { DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(1.0D, "S1", "Category 1"); dataset1.addValue(4D, "S1", "Category 2"); dataset1.addValue(3D, "S1", "Category 3"); dataset1.addValue(5D, "S1", "Category 4"); dataset1.addValue(5D, "S1", "Category 5"); dataset1.addValue(7D, "S1", "Category 6"); dataset1.addValue(7D, "S1", "Category 7"); dataset1.addValue(8D, "S1", "Category 8"); dataset1.addValue(5D, "S2", "Category 1"); dataset1.addValue(7D, "S2", "Category 2"); dataset1.addValue(6D, "S2", "Category 3"); dataset1.addValue(8D, "S2", "Category 4"); dataset1.addValue(4D, "S2", "Category 5"); dataset1.addValue(4D, "S2", "Category 6"); dataset1.addValue(2D, "S2", "Category 7"); dataset1.addValue(1.0D, "S2", "Category 8"); DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.addValue(9D, "T1", "Category 1"); dataset2.addValue(7D, "T1", "Category 2"); dataset2.addValue(2D, "T1", "Category 3"); dataset2.addValue(6D, "T1", "Category 4"); dataset2.addValue(6D, "T1", "Category 5"); dataset2.addValue(9D, "T1", "Category 6"); dataset2.addValue(5D, "T1", "Category 7"); dataset2.addValue(4D, "T1", "Category 8"); DefaultCategoryDataset dataset3 = new DefaultCategoryDataset(); dataset3.addValue(94D, "R1", "Category 1"); dataset3.addValue(75D, "R1", "Category 2"); dataset3.addValue(22D, "R1", "Category 3"); dataset3.addValue(74D, "R1", "Category 4"); dataset3.addValue(83D, "R1", "Category 5"); dataset3.addValue(9D, "R1", "Category 6"); dataset3.addValue(23D, "R1", "Category 7"); dataset3.addValue(98D, "R1", "Category 8"); ///*from w w w.j a v a 2s. co m*/ StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(); BarRenderer renderer1 = new BarRenderer(); renderer1.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); renderer1.setBaseItemLabelsVisible(true); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); LineAndShapeRenderer renderer3 = new LineAndShapeRenderer(); //plot CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset1); plot.setRenderer(renderer1); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setDataset(2, dataset3); plot.setRenderer(2, renderer3); plot.setDomainAxis(new CategoryAxis("Category")); //more rangeAxis plot.setRangeAxis(new NumberAxis("Value")); plot.setRangeAxis(1, new NumberAxis("Axis 2")); plot.mapDatasetToRangeAxis(2, 1); // plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); //chart JFreeChart chart = new JFreeChart(plot); chart.setTitle("Overlaid Bar Chart"); return chart; }
From source file:org.fhaes.fhrecorder.view.GraphSummaryOverlay.java
/** * This method creates the JFreeChart based on all of the incoming data sets. * //from ww w . jav a 2 s . co m * @param eventsDataset This is the data set corresponding to the events bar chart graph. * @param recordersDataset This is the data set corresponding to the recorders line graph. * @param samplesDataset This is the data set corresponding to the samples line graph. * @return This returns a JFreeChart with all 3 of the graphs described. */ private static JFreeChart createChart(final CategoryDataset eventsDataset, final CategoryDataset recordersDataset, final CategoryDataset samplesDataset) { final CategoryItemRenderer eventsRenderer = new BarRenderer(); ((BarRenderer) eventsRenderer).setBarPainter(new StandardBarPainter()); // Remove shine ((BarRenderer) eventsRenderer).setShadowVisible(false); eventsRenderer.setSeriesPaint(0, new Color(224, 0, 51)); eventsRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(); plot.setDataset(eventsDataset); plot.setRenderer(eventsRenderer); plot.setDomainAxis(new CategoryAxis("")); plot.setRangeAxis(new NumberAxis("")); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainAxis(new NumericCategoryAxis()); plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); final CategoryItemRenderer recorderRenderer = new LineAndShapeRenderer(true, false); recorderRenderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); recorderRenderer.setSeriesPaint(0, new Color(102, 102, 255)); recorderRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); // Temporarily removing recorders dataset // plot.setDataset(1, recordersDataset); // plot.setRenderer(1, recorderRenderer); final CategoryItemRenderer samplesRenderer = new LineAndShapeRenderer(true, false); samplesRenderer.setSeriesStroke(0, new BasicStroke(2.0f)); samplesRenderer.setSeriesPaint(0, new Color(0, 153, 0)); samplesRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setDataset(2, samplesDataset); plot.setRenderer(2, samplesRenderer); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90); plot.getDomainAxis().setLowerMargin(0.025); plot.getDomainAxis().setUpperMargin(0.025); final JFreeChart chart = new JFreeChart(plot); return chart; }
From source file:com.thalesgroup.hudson.plugins.sourcemonitor.SourceMonitorChartBuilder.java
public static JFreeChart buildChart(SourceMonitorBuildAction action) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of errors", buildDataset(action), PlotOrientation.VERTICAL, true, false, true); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null);//from w w w . j a v a2 s . c om plot.setForegroundAlpha(0.8f); 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); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer(); SourceMonitorRenderer renderer = new SourceMonitorRenderer(action.getUrlName()); plot.setRenderer(firstRender); return chart; }
From source file:de.laures.cewolf.taglib.CewolfChartFactory.java
public static JFreeChart getOverlaidChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, int xAxisType, int yAxisType, List plotDefinitions) throws ChartValidationException, DatasetProduceException { final int chartTypeConst = getChartTypeConstant(chartType); final AxisFactory axisFactory = AxisFactory.getInstance(); switch (chartTypeConst) { case OVERLAY_XY: ValueAxis domainAxis = (ValueAxis) axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType, xAxisLabel);//from w w w. ja v a 2 s .c o m // get main plot PlotDefinition mainPlotDef = (PlotDefinition) plotDefinitions.get(0); check((Dataset) mainPlotDef.getDataset(), XYDataset.class, chartType); XYPlot plot = (XYPlot) mainPlotDef.getPlot(chartTypeConst); plot.setDomainAxis(domainAxis); plot.setRangeAxis((ValueAxis) axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel)); //plot.setRenderer(new StandardXYItemRenderer()); // add second and later datasets to main plot for (int plotidx = 1; plotidx < plotDefinitions.size(); plotidx++) { PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx); check((Dataset) subPlotDef.getDataset(), XYDataset.class, chartType); plot.setDataset(plotidx, (XYDataset) subPlotDef.getDataset()); int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType()); XYItemRenderer rend = (XYItemRenderer) PlotTypes.getRenderer(rendererIndex); plot.setRenderer(plotidx, rend); } return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); case OVERLAY_CATEGORY://added by lrh 2005-07-11 CategoryAxis domainAxis2 = (CategoryAxis) axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType, xAxisLabel); // get main plot mainPlotDef = (PlotDefinition) plotDefinitions.get(0); check((Dataset) mainPlotDef.getDataset(), CategoryDataset.class, chartType); CategoryPlot plot2 = (CategoryPlot) mainPlotDef.getPlot(chartTypeConst); plot2.setDomainAxis(domainAxis2); plot2.setRangeAxis((ValueAxis) axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel)); //plot.setRenderer(new StandardXYItemRenderer()); // add second and later datasets to main plot for (int plotidx = 1; plotidx < plotDefinitions.size(); plotidx++) { PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx); check((Dataset) subPlotDef.getDataset(), CategoryDataset.class, chartType); plot2.setDataset(plotidx, (CategoryDataset) subPlotDef.getDataset()); int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType()); CategoryItemRenderer rend2 = (CategoryItemRenderer) PlotTypes.getRenderer(rendererIndex); plot2.setRenderer(plotidx, rend2); } return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot2, true); default: throw new UnsupportedChartTypeException(chartType + " is not supported."); } }
From source file:org.jenkinsci.plugins.todos.TodosChartBuilder.java
/** * Build a trend chart from the provided data. * /*ww w . j av a2s . co m*/ * @param action * the build action * @return the trend chart */ public static JFreeChart buildChart(TodosBuildAction action) { String strComments = Messages.Todos_ReportSummary_Comments(); JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, strComments, buildDataset(action), PlotOrientation.VERTICAL, true, false, true); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(0.8f); 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); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); TodosAreaRenderer renderer = new TodosAreaRenderer(action.getUrlName()); plot.setRenderer(renderer); return chart; }
From source file:soap.ui.stats.OverLaidBarChartFactory.java
public static JFreeChart createDualBarAndLineDiagram(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset barDiagramDataset, LinkedList lineDiagramDatasets) { CategoryPlot plot = new CategoryPlot(); int inc = 0;/* w w w . j a va 2 s . com*/ BarRenderer barRenderer = null; if (barDiagramDataset != null) { plot.setDataset(barDiagramDataset); barRenderer = new BarRenderer3D(); barRenderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setRenderer(barRenderer); inc = 1; plot.setDomainAxis(new CategoryAxis3D(categoryAxisLabel)); plot.setRangeAxis(new NumberAxis3D(valueAxisLabel)); } else { plot.setDomainAxis(new CategoryAxis(categoryAxisLabel)); plot.setRangeAxis(new NumberAxis(valueAxisLabel)); } plot.mapDatasetToRangeAxis(0, 0); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); CategoryItemRenderer renderers[] = new LineAndShapeRenderer[lineDiagramDatasets.size()]; for (int i = 0; i < lineDiagramDatasets.size(); i++) { CategoryDataset lineDiagramDataset = (CategoryDataset) lineDiagramDatasets.get(i); plot.setDataset(i + inc, lineDiagramDataset); plot.mapDatasetToRangeAxis(i + inc, 0); if (barDiagramDataset != null && i < barDiagramDataset.getRowCount()) { renderers[i] = new LineAndShapeRendererMapToBar(barRenderer, i); } else { renderers[i] = new LineAndShapeRenderer(); } renderers[i].setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderers[i].setSeriesStroke(0, new BasicStroke(1.5f)); renderers[i].setSeriesStroke(1, new BasicStroke(1.5f)); plot.setRenderer(i + inc, renderers[i]); } CategoryDataset dataset; if (lineDiagramDatasets.size() > 0) dataset = (CategoryDataset) lineDiagramDatasets.get(0); else dataset = barDiagramDataset; for (int i = 0; i < dataset.getColumnCount(); i++) plot.getDomainAxis().addCategoryLabelToolTip(dataset.getColumnKey(i), (String) dataset.getColumnKey(i)); plot.setRangeGridlinePaint(Color.black); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); JFreeChart chart = new JFreeChart(plot); chart.setTitle(title); chart.setLegend(new StandardLegend()); return chart; }
From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsPredictionDecomposed.java
private static JFreeChart createChart() { ////from w w w . ja va 2 s.co m DefaultCategoryDataset Pactual = jFreeChartDataSets.get(CoreConfiguration.PACTUAL_LABEL); DefaultCategoryDataset Ppredicted = jFreeChartDataSets.get(CoreConfiguration.PPREDICTED_LABEL); StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(); LineAndShapeRenderer renderer1 = new LineAndShapeRenderer(); /*renderer1.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); renderer1.setBaseItemLabelsVisible(true);*/ StackedAreaRenderer renderer2 = new StackedAreaRenderer(); //plot CategoryPlot plot = new CategoryPlot(); plot.setDataset(Ppredicted); plot.setRenderer(renderer2); plot.setDataset(1, Pactual); plot.setRenderer(1, renderer1); CategoryAxis axis = new CategoryAxis("Sample"); axis.setTickLabelsVisible(false); axis.setCategoryMargin(0.0); plot.setDomainAxis(axis); //more rangeAxis plot.setRangeAxis(new NumberAxis("Power (Watts)")); plot.mapDatasetToRangeAxis(2, 1); // plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); //chart JFreeChart chart = new JFreeChart(plot); chart.setTitle(NAME); return chart; }