List of usage examples for org.jfree.chart StandardChartTheme setBarPainter
public void setBarPainter(BarPainter painter)
From source file:org.drugis.addis.gui.GUIFactory.java
public static void configureJFreeChartLookAndFeel() { StandardChartTheme chartTheme = new StandardChartTheme("ADDIS"); chartTheme.setBarPainter(new StandardBarPainter()); chartTheme.setShadowVisible(false);//from w w w .j a v a 2s.c om ChartFactory.setChartTheme(chartTheme); }
From source file:com.uttesh.pdfngreport.util.chart.ChartStyle.java
/** * this method will set the style theme for pie chart. * * @see org.jfree.chart.StandardChartTheme * @param chart/*from w w w .ja va 2 s .c o m*/ */ public static void theme(JFreeChart chart) { String fontName = "Lucida Sans"; StandardChartTheme theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setTitlePaint(Color.decode("#4572a7")); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 16)); //title theme.setLargeFont(new Font(fontName, Font.BOLD, 15)); //axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 11)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); chart.setTextAntiAlias(true); chart.setAntiAlias(true); }
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."); }/*w w w . jav a2s.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); } }); }