Example usage for org.jfree.chart ChartFactory getChartTheme

List of usage examples for org.jfree.chart ChartFactory getChartTheme

Introduction

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

Prototype

public static ChartTheme getChartTheme() 

Source Link

Document

Returns the current chart theme used by the factory.

Usage

From source file:com.bdb.weather.display.windrose.WindRosePane.java

/**
 * Constructor./*w  w  w. j  a  v  a 2s .  com*/
 */
public WindRosePane() {
    this.setPrefSize(300, 300);
    ChartFactory.getChartTheme().apply(chart);
    chartViewer.setMinHeight(10);
    chartViewer.setMinWidth(10);
    chartViewer.setPrefSize(300, 300);

    dataTable = new TableView();

    FlowPane summaryPanel = new FlowPane();

    summaryPanel.getChildren().add(new LabeledFieldPane<>("Date:", timeField));
    timeField.setEditable(false);
    summaryPanel.getChildren().add(new LabeledFieldPane<>("% Winds are calm:", calmField));
    calmField.setEditable(false);

    summaryPanel.getChildren().add(new Label("Speeds are in " + Speed.getDefaultUnit()));

    BorderPane p = new BorderPane();

    p.setCenter(dataTable);
    p.setTop(summaryPanel);
    this.setTabContents(chartViewer, p);

    TableColumn<WindSlice, String> headingColumn = new TableColumn<>("Heading");
    headingColumn.setCellValueFactory((rec) -> new ReadOnlyStringWrapper(
            Heading.headingForSlice(rec.getValue().getHeadingIndex(), 16).getCompassLabel()));
    dataTable.getColumns().add(headingColumn);

    TableColumn<WindSlice, String> percentOfWindColumn = new TableColumn<>("% of Wind");
    percentOfWindColumn.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(String.format("%.1f", rec.getValue().getPercentageOfWind())));
    dataTable.getColumns().add(percentOfWindColumn);

    TableColumn<WindSlice, Speed> avgSpeedColumn = new TableColumn<>("Avg Speed");
    avgSpeedColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper<>(rec.getValue().getAvgSpeed()));
    dataTable.getColumns().add(avgSpeedColumn);

    TableColumn<WindSlice, Speed> maxSpeedColumn = new TableColumn<>("Max Speed");
    maxSpeedColumn.setCellValueFactory((rec) -> new ReadOnlyObjectWrapper<>(rec.getValue().getMaxSpeed()));
    dataTable.getColumns().add(maxSpeedColumn);

}

From source file:de.fub.maps.project.detector.model.inference.ui.charts.ClassificationBarChart.java

/**
 * Creates new form ClassificationBarChart
 *//*  w  w  w .j ava2  s .  c  o  m*/
public ClassificationBarChart() {
    super();
    initComponents();
    plot = new CustomCategoryPlot();
    barChart = new JFreeChart(NbBundle.getMessage(ClassificationBarChart.class, "CLT_Chart_Classify_Name"),
            null, plot, true);
    ChartFactory.getChartTheme().apply(barChart);
    plot.setDomainAxis(new CategoryAxis());
    plot.getDomainAxis().setLabel(NbBundle.getMessage(ClassificationBarChart.class, "CLT_Doman_Axis_Name"));
    plot.setOrientation(PlotOrientation.VERTICAL);

    Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14);
    barChart.getTitle().setFont(font);
    barChart.getTitle().setPaint(new Color(153, 153, 153));

    plot.setDataset(0, relDataset);
    plot.setDataset(1, absDataset);
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 1);

    NumberAxis relAxis = new NumberAxis(
            NbBundle.getMessage(ClassificationBarChart.class, "CLT_Value_Axis_Name"));
    relAxis.setAutoRange(true);
    relAxis.setUpperMargin(.20);
    NumberAxis absAxis = new NumberAxis(
            NbBundle.getMessage(ClassificationBarChart.class, "CLT_Value_Rel_Axis_Name"));
    absAxis.setAutoRange(true);
    absAxis.setUpperMargin(.20);

    plot.setRangeAxis(0, relAxis);
    plot.setRangeAxis(1, absAxis);
    plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
    plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);

    BarRenderer relRenderer = new BarRenderer();
    relRenderer.setBasePaint(relColor);
    relRenderer.setAutoPopulateSeriesPaint(false);
    relRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    relRenderer.setBarPainter(new StandardBarPainter());
    relRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    relRenderer.setBaseItemLabelsVisible(true);

    BarRenderer absRenderer = new BarRenderer();
    absRenderer.setBasePaint(absColor);
    absRenderer.setAutoPopulateSeriesPaint(false);
    absRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    absRenderer.setBarPainter(new StandardBarPainter());
    absRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
            StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat()));
    absRenderer.setBaseItemLabelsVisible(true);

    plot.setRenderer(0, relRenderer);
    plot.setRenderer(1, absRenderer);

    plot.setBackgroundPaint(Color.white);
    barChart.setBackgroundPaint(Color.white);
    plot.setRangeGridlinesVisible(false);
    chartPanel = new ChartPanel(barChart, false);
    chartPanel.setVerticalAxisTrace(false);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setBackground(Color.white);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:com.bdb.weather.display.day.ItemRenderer.java

public WindDirPane() {
    setPrefSize(300, 300);//from  www.  j  av  a2 s .c  om
    JFreeChart chart = ChartFactory.createPolarChart(null, null, false, true, false);

    ChartFactory.getChartTheme().apply(chart);

    plot = (PolarPlot) chart.getPlot();

    ItemRenderer renderer = new ItemRenderer();
    XYToolTipGenerator ttg = (XYDataset dataset, int series, int item) -> {
        double time = dataset.getXValue(series, item);
        long millis = Math.round(time);
        return "" + millis;
    };
    renderer.setBaseToolTipGenerator(ttg);
    plot.setRenderer(renderer);

    ((NumberAxis) plot.getAxis()).setRange(-240.0, 60.0 * 24);
    ((NumberAxis) plot.getAxis()).setAutoRange(false);
    ((NumberAxis) plot.getAxis()).setTickUnit(new NumberTickUnit(240.0, new DecimalFormat("00")) {
        @Override
        public String valueToString(double number) {
            if (number < 0.0 || (int) number % 240 != 0)
                return "";
            else
                return super.valueToString(number / 60.0);
        }
    });

    ChartViewer chartViewer = new ChartViewer(chart);
    this.setTabContents(chartViewer, table);

    plot.setDataset(new XYSeriesCollection(windDirSeries));

    TableColumn<HistoricalRecord, String> column = new TableColumn<>("Time");
    column.setCellValueFactory((rec) -> new ReadOnlyStringWrapper(
            DisplayConstants.formatTime(rec.getValue().getTime().toLocalTime())));
    table.getColumns().add(column);

    column = new TableColumn<>("Direction");
    column.setCellValueFactory(
            (rec) -> new ReadOnlyStringWrapper(rec.getValue().getAvgWind().getDirection().getCompassLabel()));
    table.getColumns().add(column);
}

From source file:com.bdb.weather.display.stripchart.StripChart.java

/**
 * Constructor.// www .j av  a 2 s.c o  m
 * 
 * @param leftAxisType The type of data that is associated with the left axis
 * @param rightAxisType The type of data that is associated with the right axis
 * @param categorySpanHours How many hours that the X axis should initially display
 * @param maxSpanHours The maximum amount of data to keep in the plots dataset
 */
public StripChart(MeasurementType leftAxisType, MeasurementType rightAxisType, int categorySpanHours,
        int maxSpanHours) {
    span = categorySpanHours;
    this.maxSpanHours = maxSpanHours;

    //
    // Set up the Y axes
    //
    setLeftAxis(leftAxisType);
    setRightAxis(leftAxisType);

    //
    // Set up the X axis
    //
    dateAxis = new DateAxis("Time");
    dateAxis.setAutoRange(false);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("h:mm a"));
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setUpperMargin(.10);

    plot.setDomainAxis(dateAxis);
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 1);
    adjustDateAxis(Calendar.getInstance());

    chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    ChartFactory.getChartTheme().apply(chart);
    chartViewer = new ChartViewer(chart);
    this.setCenter(chartViewer);

    chart.getLegend().setPosition(RectangleEdge.RIGHT);
}

From source file:sim.util.media.chart.BoxPlotGenerator.java

protected void buildChart() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    // we build the chart manually rather than using ChartFactory
    // because we need to customize the getDataRange method below

    CategoryAxis categoryAxis = new CategoryAxis("");
    NumberAxis valueAxis = new NumberAxis("Untitled Y Axis");
    valueAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) {
        // Customizing this method in order to provide a bit of
        // vertical buffer.  Otherwise the bar chart box gets drawn
        // slightly off-chart, which looks really bad.

        public Range getDataRange(ValueAxis axis) {
            Range range = super.getDataRange(axis);
            if (range == null)
                return null;
            final double EXTRA_PERCENTAGE = 0.02;
            return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE);
        }//from w w w  .  j av a  2  s. c o  m
    };

    chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    ChartFactory.getChartTheme().apply(chart);

    chart.setAntiAlias(true);
    chartPanel = buildChartPanel(chart);
    setChartPanel(chartPanel);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}

From source file:edu.gmu.cs.sim.util.media.chart.BoxPlotGenerator.java

protected void buildChart() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    // we build the chart manually rather than using ChartFactory
    // because we need to customize the getDataRange method below

    CategoryAxis categoryAxis = new CategoryAxis("");
    NumberAxis valueAxis = new NumberAxis("Untitled Y Axis");
    valueAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) {
        // Customizing this method in order to provide a bit of
        // vertical buffer.  Otherwise the bar chart box gets drawn
        // slightly off-chart, which looks really bad.

        public Range getDataRange(ValueAxis axis) {
            Range range = super.getDataRange(axis);
            if (range == null) {
                return null;
            }//w  w  w . java  2 s  .  c o m
            final double EXTRA_PERCENTAGE = 0.02;
            return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE);
        }
    };

    chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    ChartFactory.getChartTheme().apply(chart);

    chart.setAntiAlias(true);
    chartPanel = buildChartPanel(chart);
    setChartPanel(chartPanel);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}

From source file:com.redhat.thermostat.byteman.chart.swing.SwingBarChart.java

private JFreeChart createChart(Collection<PlotRecord> records) {
    // data//from  www.j  a v  a  2  s . co  m
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    for (PlotRecord re : records) {
        Long label = re.getPeriodStart() + ((re.getPeriodEnd() - re.getPeriodStart()) / 2);
        ds.addValue(re.getValue(), re.getCategory(), label);
    }
    // chart
    BarRenderer3D br = new StackedBarRenderer3D(cf.rendered3dXOffset, cf.rendered3dYOffset);
    ZoomablePlot plot = new ZoomablePlot(zm, ds, new CategoryAxis(), new NumberAxis(), br);
    plot.setOrientation(PlotOrientation.VERTICAL);
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    ChartFactory.getChartTheme().apply(chart);
    // renderer
    br.setSeriesPaint(0, toColor(cf.seriesPaint0));
    br.setSeriesPaint(1, toColor(cf.seriesPaint1));
    br.setSeriesPaint(2, toColor(cf.seriesPaint2));
    br.setSeriesPaint(3, toColor(cf.seriesPaint3));
    br.setSeriesPaint(4, toColor(cf.seriesPaint4));
    br.setSeriesPaint(5, toColor(cf.seriesPaint5));
    br.setWallPaint(toColor(cf.wallPaint));
    br.setBaseItemLabelsVisible(cf.baseItemLabelsVisible);
    br.setShadowVisible(cf.shadowVisible);
    br.setItemMargin(cf.itemMargin);
    // plot
    plot.setBackgroundPaint(toColor(cf.backgroundPaint));
    plot.setBackgroundImageAlpha((float) cf.backgroundImageAlpha);
    plot.setDomainGridlinesVisible(cf.domainGridlinesVisible);
    plot.setRangeGridlinePaint(toColor(cf.rangeGridlinePaint));
    //        plot.getRangeAxis().setRange(new Range(ds.getMin(), ds.getMax() * 1.1));
    plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.getRangeAxis().setLabel(cf.rangeAxisLabel);
    colorAxis(plot.getRangeAxis());
    colorAxis(plot.getDomainAxis());
    plot.getDomainAxis().setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(Math.PI * cf.domainAxisLabelAngle));
    plot.getDomainAxis().setLowerMargin(cf.domainAxisLowerMargin);
    plot.getDomainAxis().setUpperMargin(cf.domainAxisUpperMargin);
    plot.getDomainAxis().setLabel(cf.domainAxisLabel);
    plot.setOutlineVisible(cf.outlineVisible);

    return chart;
}

From source file:com.bdb.weather.display.day.DayXYPlotPane.java

private void createChartElements() {
    ///*from w  w w  .  j  a  v a 2s  .c om*/
    // Set up the Domain Axis (X)
    //
    plot = new XYPlot();
    dateAxis = new DateAxis("Time");
    dateAxis.setAutoRange(false);
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1, new SimpleDateFormat("h a")));
    dateAxis.setVerticalTickLabels(true);
    plot.setDomainAxis(dateAxis);
    plot.setRangeAxis(leftAxis);
    plot.setDataset(0, datasetLeft);
    if (rightAxis != null) {
        plot.setRangeAxis(1, rightAxis);
        plot.mapDatasetToRangeAxis(1, 1);
        plot.setDataset(1, datasetRight);
    }
    plot.setNoDataMessage("There is no data for the specified day");

    //
    // Set up the renderer to generate tool tips, not show shapes
    //
    XYLineAndShapeRenderer renderer = new XYLine3DRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    //renderer.setDefaultEntityRadius(1);
    plot.setRenderer(0, renderer);

    renderer = new XYLine3DRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    //renderer.setDefaultEntityRadius(1);
    plot.setRenderer(1, renderer);

    //
    // Setup the cross hairs that are displayed when the user clicks on the plot
    //
    plot.setRangeCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairVisible(true);

    //
    // Create the chart that contains the plot and the panel that contains the chart
    //
    chart = new JFreeChart(plot);
    ChartFactory.getChartTheme().apply(chart);
    chartViewer = new ChartViewer(chart);

    chartViewer.setMaxHeight(500);
    chartViewer.setMaxWidth(800);

    //
    // Add the Day/Night indicator option to the chart panels context menu
    //
    ContextMenu menu = chartViewer.getContextMenu();

    displayMenu = new Menu("Display");

    dayNightItem = new CheckMenuItem("Day/Night Indicators");
    dayNightItem.setSelected(true);
    displayMenu.getItems().add(dayNightItem);
    dayNightItem.setOnAction(this);
    menu.getItems().add(displayMenu);
}

From source file:org.moeaframework.analysis.plot.Plot.java

/**
 * If the chart has not yet been initialized, creates a chart for XY data.
 * If the chart is already initialized, checks if the chart is for XY data.
 * //from w w  w .  j a  v a 2 s .  com
 * @throws FrameworkException if the chart does not support XY data
 */
private void createXYPlot() {
    if (chart == null) {
        NumberAxis xAxis = new NumberAxis("");
        xAxis.setAutoRangeIncludesZero(false);
        NumberAxis yAxis = new NumberAxis("");
        yAxis.setAutoRangeIncludesZero(false);

        XYPlot plot = new XYPlot();
        plot.setDomainAxis(xAxis);
        plot.setRangeAxis(yAxis);

        XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();

        XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);
        renderer.setBaseToolTipGenerator(toolTipGenerator);
        plot.setRenderer(renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);

        chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        ChartFactory.getChartTheme().apply(chart);
    } else if (!(chart.getPlot() instanceof XYPlot)) {
        throw new FrameworkException("Can not combine XY plot and categorial plot");
    }
}

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./*  w  ww  . j a  v  a2 s. c  o  m*/
 * 
 * @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");
    }
}