Example usage for org.jfree.chart StandardChartTheme StandardChartTheme

List of usage examples for org.jfree.chart StandardChartTheme StandardChartTheme

Introduction

In this page you can find the example usage for org.jfree.chart StandardChartTheme StandardChartTheme.

Prototype

public StandardChartTheme(String name, boolean shadow) 

Source Link

Document

Creates a new default instance.

Usage

From source file:uom.research.thalassemia.util.PieChartCreator.java

/**
 * Creates a panel for the demo (used by SuperDemo.java).
 *
 * @param pPieDataset dataset/* w w w.j av a  2  s  .co  m*/
 * @param pTitle title
 * @return A panel.
 */
public JPanel createPanel(final PieDataset pPieDataset, final String pTitle) {
    title = pTitle;
    pieDataset = pPieDataset;

    // set a theme using the new shadow generator feature available in
    // 1.0.14 - for backwards compatibility it is not enabled by default
    ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true));
    JFreeChart chart = createChart(pieDataset);
    chart.setPadding(new RectangleInsets(4, 8, 2, 2));
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    panel.setPreferredSize(new Dimension(600, 300));
    return panel;
}

From source file:speedbagalg.OscopeView.java

/**
 * Creates new form OscopeView//from   www . j  a  v  a2 s  .  c o  m
 */
/*    
    public OscopeView(String fileName)
    {
this.fileName = fileName;
initComponents();
updateThread = new RunnableMember2(this, "updateGUI");
ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true));
// create a dataset...
int maxAge = 2400;
this.xData = new TimeSeries("X axis");
this.xData.setMaximumItemAge(maxAge);
this.yData = new TimeSeries("Y axis");
this.yData.setMaximumItemAge(maxAge);
this.zData = new TimeSeries("Z axis");
this.zData.setMaximumItemAge(maxAge);
this.averageData = new TimeSeries("Avg. Data");
this.averageData.setMaximumItemAge(maxAge);
//this.windSpeedSeries = new TimeSeries("Wind Speed");
//this.windSpeedSeries.setMaximumItemAge(maxAge);
//this.rainSeries = new TimeSeries("Rain 24hrs");
//this.rainSeries.setMaximumItemAge(maxAge);
        
final TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(xData);
dataset.addSeries(yData);
dataset.addSeries(zData);
dataset.addSeries(averageData);
        
//dataset.addSeries(windSpeedSeries);
//dataset.addSeries(rainSeries);
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Accel Data",
        "Time",
        "Value",
        dataset,
        true,
        true,
        false);
final XYPlot plot = chart.getXYPlot();
        
ValueAxis axis = plot.getDomainAxis();
axis.setAutoRange(true);
axis = plot.getRangeAxis();
axis.setRange(-1000.0, 10000.0);
        
chart.setBackgroundPaint(Color.white);
        
//XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
        
// create and display a frame...
thePanel = new ChartPanel(chart);
        
Dimension d = new Dimension(200, 100);
thePanel.setSize(d);
thePanel.setPreferredSize(d);
BorderLayout layout = new BorderLayout();
jPanelOscope.setLayout(layout);
jPanelOscope.add(thePanel, BorderLayout.CENTER);
        
plotXCheckBox.setSelected(plotX);
plotYCheckBox.setSelected(plotY);
plotZCheckBox.setSelected(plotZ);
    }
*/
public OscopeView(String fileName) {
    this.fileName = fileName;
    initComponents();
    updateThread = new RunnableMember2(this, "updateGUI");
    ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true));
    // create a dataset...
    this.xData = new XYSeries("Min");
    //this.xData.setMaximumItemAge(maxAge);
    this.yData = new XYSeries("Peak");
    //this.yData.setMaximumItemAge(maxAge);
    this.zData = new XYSeries("Z axis");
    //this.zData.setMaximumItemAge(maxAge);
    this.averageData = new XYSeries("Avg. Data");
    //this.averageData.setMaximumItemAge(maxAge);
    //this.windSpeedSeries = new TimeSeries("Wind Speed");
    //this.windSpeedSeries.setMaximumItemAge(maxAge);
    //this.rainSeries = new TimeSeries("Rain 24hrs");
    //this.rainSeries.setMaximumItemAge(maxAge);

    final XYSeriesCollection dataset = new XYSeriesCollection();
    //SlidingCategoryDataset dataset = new SlidingCategoryDataset(0, 10);
    dataset.addSeries(xData);
    dataset.addSeries(yData);
    dataset.addSeries(zData);
    dataset.addSeries(averageData);

    //dataset.addSeries(windSpeedSeries);
    //dataset.addSeries(rainSeries);
    chart = ChartFactory.createXYLineChart("Accel Data", "Time", "Value", dataset, PlotOrientation.VERTICAL,
            true, true, false);
    final XYPlot plot = chart.getXYPlot();

    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(false);
    axis.setRange(minStart, maxDomain);
    axis = plot.getRangeAxis();
    axis.setRange(vMin, vMax);

    chart.setBackgroundPaint(Color.white);

    //XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    // create and display a frame...
    thePanel = new ChartPanel(chart);

    Dimension d = new Dimension(200, 100);
    thePanel.setSize(d);
    thePanel.setPreferredSize(d);
    BorderLayout layout = new BorderLayout();
    jPanelOscope.setLayout(layout);
    jPanelOscope.add(thePanel, BorderLayout.CENTER);

    plotXCheckBox.setSelected(plotX);
    plotYCheckBox.setSelected(plotY);
    plotZCheckBox.setSelected(plotZ);

    vMaxSpinner.setValue(vMax);
}

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.");
        }/*from  ww  w  .j  a  v a2s. c om*/

        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);
        }
    });

}