Example usage for org.jfree.chart.plot XYPlot setDomainCrosshairStroke

List of usage examples for org.jfree.chart.plot XYPlot setDomainCrosshairStroke

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setDomainCrosshairStroke.

Prototype

public void setDomainCrosshairStroke(Stroke stroke) 

Source Link

Document

Sets the Stroke used to draw the crosshairs (if visible) and notifies registered listeners that the axis has been modified.

Usage

From source file:org.webcat.grader.graphs.HistogramChart.java

protected JFreeChart generateChart(WCChartTheme chartTheme) {
    JFreeChart chart = ChartFactory.createHistogram(null, xAxisLabel(), yAxisLabel(), intervalXYDataset(),
            orientation(), false, false, false);

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setAutoPopulateSeriesOutlinePaint(true);
    renderer.setDrawBarOutline(true);/*from  www  . jav  a 2  s.  c o  m*/
    renderer.setShadowVisible(false);

    if (markValue != null) {
        plot.setDomainCrosshairVisible(true);
        plot.setDomainCrosshairValue(markValue.doubleValue());
        plot.setDomainCrosshairPaint(Color.red);
        plot.setDomainCrosshairStroke(MARKER_STROKE);
    }

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:net.nikr.eve.jeveasset.gui.tabs.tracker.TrackerTab.java

public TrackerTab(Program program) {
    super(program, TabsTracker.get().title(), Images.TOOL_TRACKER.getIcon(), true);

    filterDialog = new TrackerFilterDialog(program);

    jPopupMenu = new JPopupMenu();
    jPopupMenu.addPopupMenuListener(listener);

    JMenuItem jMenuItem;/*ww  w . ja va2  s . co m*/
    jMenuItem = new JMenuItem(TabsTracker.get().edit(), Images.EDIT_EDIT.getIcon());
    jMenuItem.setActionCommand(TrackerAction.EDIT.name());
    jMenuItem.addActionListener(listener);
    jPopupMenu.add(jMenuItem);

    jMenuItem = new JMenuItem(TabsTracker.get().delete(), Images.EDIT_DELETE.getIcon());
    jMenuItem.setActionCommand(TrackerAction.DELETE.name());
    jMenuItem.addActionListener(listener);
    jPopupMenu.add(jMenuItem);

    JMenuInfo.createDefault(jPopupMenu);

    jIskValue = new JMenuItem();
    jIskValue.setEnabled(false);
    jIskValue.setForeground(Color.BLACK);
    jIskValue.setHorizontalAlignment(SwingConstants.RIGHT);
    jIskValue.setDisabledIcon(Images.TOOL_VALUES.getIcon());
    jPopupMenu.add(jIskValue);

    jDateValue = new JMenuItem();
    jDateValue.setEnabled(false);
    jDateValue.setForeground(Color.BLACK);
    jDateValue.setHorizontalAlignment(SwingConstants.RIGHT);
    jPopupMenu.add(jDateValue);

    jEditDialog = new JTrackerEditDialog(program);

    jSelectionDialog = new JSelectionDialog(program);

    JSeparator jDateSeparator = new JSeparator();

    jQuickDate = new JComboBox<QuickDate>(QuickDate.values());
    jQuickDate.setActionCommand(TrackerAction.QUICK_DATE.name());
    jQuickDate.addActionListener(listener);

    JLabel jFromLabel = new JLabel(TabsTracker.get().from());
    jFrom = createDateChooser();

    JLabel jToLabel = new JLabel(TabsTracker.get().to());
    jTo = createDateChooser();

    jAll = new JCheckBox(General.get().all());
    jAll.setSelected(true);
    jAll.setActionCommand(TrackerAction.ALL.name());
    jAll.addActionListener(listener);
    jAll.setFont(new Font(jAll.getFont().getName(), Font.ITALIC, jAll.getFont().getSize()));

    jTotal = new JCheckBox(TabsTracker.get().total());
    jTotal.setSelected(true);
    jTotal.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jTotal.addActionListener(listener);

    jWalletBalance = new JCheckBox(TabsTracker.get().walletBalance());
    jWalletBalance.setSelected(true);
    jWalletBalance.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jWalletBalance.addActionListener(listener);

    jWalletBalanceFilters = new JButton(Images.LOC_INCLUDE.getIcon());
    jWalletBalanceFilters.setActionCommand(TrackerAction.FILTER_WALLET_BALANCE.name());
    jWalletBalanceFilters.addActionListener(listener);

    jAssets = new JCheckBox(TabsTracker.get().assets());
    jAssets.setSelected(true);
    jAssets.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jAssets.addActionListener(listener);

    jAssetsFilters = new JButton(Images.LOC_INCLUDE.getIcon());
    jAssetsFilters.setActionCommand(TrackerAction.FILTER_ASSETS.name());
    jAssetsFilters.addActionListener(listener);

    jSellOrders = new JCheckBox(TabsTracker.get().sellOrders());
    jSellOrders.setSelected(true);
    jSellOrders.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jSellOrders.addActionListener(listener);

    jEscrows = new JCheckBox(TabsTracker.get().escrows());
    jEscrows.setSelected(true);
    jEscrows.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jEscrows.addActionListener(listener);

    jEscrowsToCover = new JCheckBox(TabsTracker.get().escrowsToCover());
    jEscrowsToCover.setSelected(true);
    jEscrowsToCover.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jEscrowsToCover.addActionListener(listener);

    jManufacturing = new JCheckBox(TabsTracker.get().manufacturing());
    jManufacturing.setSelected(true);
    jManufacturing.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jManufacturing.addActionListener(listener);

    jContractCollateral = new JCheckBox(TabsTracker.get().contractCollateral());
    jContractCollateral.setSelected(true);
    jContractCollateral.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jContractCollateral.addActionListener(listener);

    jContractValue = new JCheckBox(TabsTracker.get().contractValue());
    jContractValue.setSelected(true);
    jContractValue.setActionCommand(TrackerAction.UPDATE_SHOWN.name());
    jContractValue.addActionListener(listener);

    JSeparator jOwnersSeparator = new JSeparator();

    jAllProfiles = new JCheckBox(TabsTracker.get().allProfiles());
    jAllProfiles.setActionCommand(TrackerAction.PROFILE.name());
    jAllProfiles.addActionListener(listener);

    jOwners = new JMultiSelectionList<String>();
    jOwners.getSelectionModel().addListSelectionListener(listener);
    JScrollPane jOwnersScroll = new JScrollPane(jOwners);

    JLabel jHelp = new JLabel(TabsTracker.get().help());
    jHelp.setIcon(Images.MISC_HELP.getIcon());

    JLabel jNoFilter = new JLabel(TabsTracker.get().helpLegacyData());
    jNoFilter.setIcon(new ShapeIcon(NO_FILTER));

    JLabel jFilter = new JLabel(TabsTracker.get().helpNewData());
    jFilter.setIcon(new ShapeIcon(FILTER_AND_DEFAULT));

    JDropDownButton jSettings = new JDropDownButton(Images.DIALOG_SETTINGS.getIcon());

    jIncludeZero = new JCheckBoxMenuItem(TabsTracker.get().includeZero());
    jIncludeZero.setSelected(true);
    jIncludeZero.setActionCommand(TrackerAction.INCLUDE_ZERO.name());
    jIncludeZero.addActionListener(listener);
    jSettings.add(jIncludeZero);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setDateFormatOverride(dateFormat);
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setAutoTickUnitSelection(true);
    domainAxis.setAutoRange(true);
    domainAxis.setTickLabelFont(jFromLabel.getFont());

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRange(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    rangeAxis.setTickLabelFont(jFromLabel.getFont());

    //XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, new XYLineAndShapeRenderer(true, true));
    render = new MyRender();
    XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, render);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.getRenderer()
            .setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: {2} ({1})", dateFormat, iskFormat));
    plot.setDomainCrosshairLockedOnData(true);
    plot.setDomainCrosshairStroke(new BasicStroke(1));
    plot.setDomainCrosshairPaint(Color.BLACK);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(false);

    jNextChart = new JFreeChart(plot);
    jNextChart.setAntiAlias(true);
    jNextChart.setBackgroundPaint(jPanel.getBackground());
    jNextChart.addProgressListener(null);
    jNextChart.getLegend().setItemFont(jFrom.getFont());

    jChartPanel = new ChartPanel(jNextChart);
    jChartPanel.addMouseListener(listener);
    jChartPanel.setDomainZoomable(false);
    jChartPanel.setRangeZoomable(false);
    jChartPanel.setPopupMenu(null);
    jChartPanel.addChartMouseListener(listener);
    jChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);
    jChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    jChartPanel.setMinimumDrawWidth(10);
    jChartPanel.setMinimumDrawHeight(10);

    int AssetsGapWidth = PANEL_WIDTH - jAssets.getPreferredSize().width
            - jAssetsFilters.getPreferredSize().width;
    if (AssetsGapWidth < 0) {
        AssetsGapWidth = 0;
    }
    int WalletGapWidth = PANEL_WIDTH - jWalletBalance.getPreferredSize().width
            - jWalletBalanceFilters.getPreferredSize().width;
    if (WalletGapWidth < 0) {
        WalletGapWidth = 0;
    }

    layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup()
            .addGroup(layout.createSequentialGroup().addComponent(jHelp).addGap(20).addComponent(jNoFilter)
                    .addGap(20).addComponent(jFilter).addGap(20, 20, Integer.MAX_VALUE).addComponent(jSettings)
                    .addGap(6))
            .addComponent(jChartPanel)).addGroup(
                    layout.createParallelGroup().addComponent(jQuickDate, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup()
                                            .addComponent(jFromLabel, LABEL_WIDTH, LABEL_WIDTH, LABEL_WIDTH)
                                            .addComponent(jToLabel, LABEL_WIDTH, LABEL_WIDTH, LABEL_WIDTH))
                                    .addGap(0)
                                    .addGroup(layout.createParallelGroup()
                                            .addComponent(jFrom, PANEL_WIDTH - LABEL_WIDTH,
                                                    PANEL_WIDTH - LABEL_WIDTH, PANEL_WIDTH - LABEL_WIDTH)
                                            .addComponent(jTo, PANEL_WIDTH - LABEL_WIDTH,
                                                    PANEL_WIDTH - LABEL_WIDTH, PANEL_WIDTH - LABEL_WIDTH)))
                            .addComponent(jDateSeparator, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jAll, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jTotal, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addGroup(layout.createSequentialGroup().addComponent(jWalletBalance)
                                    .addGap(0, 0, WalletGapWidth).addComponent(jWalletBalanceFilters))
                            .addGroup(layout.createSequentialGroup().addComponent(jAssets)
                                    .addGap(0, 0, AssetsGapWidth).addComponent(jAssetsFilters))
                            .addComponent(jSellOrders, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jEscrows, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jEscrowsToCover, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jManufacturing, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jContractCollateral, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jContractValue, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jOwnersSeparator, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jAllProfiles, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)
                            .addComponent(jOwnersScroll, PANEL_WIDTH, PANEL_WIDTH, PANEL_WIDTH)));
    layout.setVerticalGroup(layout.createParallelGroup()
            .addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup()
                    .addComponent(jHelp, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jNoFilter, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jFilter, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jSettings, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight()))
                    .addComponent(jChartPanel))
            .addGroup(layout.createSequentialGroup()
                    .addComponent(jQuickDate, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addGroup(layout.createParallelGroup()
                            .addComponent(jFromLabel, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight())
                            .addComponent(jFrom, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight()))
                    .addGroup(layout.createParallelGroup()
                            .addComponent(jToLabel, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight())
                            .addComponent(jTo, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight()))
                    .addComponent(jDateSeparator, 3, 3, 3)
                    .addComponent(jAll, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jTotal, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addGroup(layout.createParallelGroup()
                            .addComponent(jWalletBalance, Program.getButtonsHeight(),
                                    Program.getButtonsHeight(), Program.getButtonsHeight())
                            .addComponent(jWalletBalanceFilters, Program.getButtonsHeight(),
                                    Program.getButtonsHeight(), Program.getButtonsHeight()))
                    .addGroup(layout.createParallelGroup()
                            .addComponent(jAssets, Program.getButtonsHeight(), Program.getButtonsHeight(),
                                    Program.getButtonsHeight())
                            .addComponent(jAssetsFilters, Program.getButtonsHeight(),
                                    Program.getButtonsHeight(), Program.getButtonsHeight()))
                    .addComponent(jSellOrders, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jEscrows, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jEscrowsToCover, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jManufacturing, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jContractCollateral, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jContractValue, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jOwnersSeparator, 3, 3, 3)
                    .addComponent(jAllProfiles, Program.getButtonsHeight(), Program.getButtonsHeight(),
                            Program.getButtonsHeight())
                    .addComponent(jOwnersScroll, 70, 70, Integer.MAX_VALUE)));
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.GpsScatterPlotUIComponent.java

/***********************************************************************************************
 * Customise the XYPlot of a new chart, e.g. for fixed range axes.
 * Remember that a GPS Scatter Plot has no ChannelSelector.
 *
 * @param datasettype/* w w  w  .j  a  v a  2  s  .c om*/
 * @param primarydataset
 * @param secondarydatasets
 * @param updatetype
 * @param displaylimit
 * @param channelselector
 * @param debug
 *
 * @return JFreeChart
 */

public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset,
        final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit,
        final ChannelSelectorUIComponentInterface channelselector, final boolean debug) {
    final String SOURCE = "GpsScatterPlotUIComponent.createCustomisedChart() ";
    final JFreeChart jFreeChart;
    final XYPlot plot;
    final Stroke strokeCrosshair;
    final XYDotRenderer renderer;
    final ValueAxis axisRange;
    final NumberAxis axisDomain;

    // See ChartHelper for other calls to ChartFactory
    // Note that no ChannelSector means no way to control the legend, so turn it off
    jFreeChart = ChartFactory.createScatterPlot(MSG_WAITING_FOR_DATA, MSG_WAITING_FOR_DATA,
            MSG_WAITING_FOR_DATA, primarydataset, PlotOrientation.VERTICAL, false, //channelselector.hasLegend(),
            true, false);

    jFreeChart.setBackgroundPaint(UIComponentPlugin.DEFAULT_COLOUR_CANVAS.getColor());

    // Experimental chart configuration
    jFreeChart.getTitle().setFont(UIComponentPlugin.DEFAULT_FONT.getFont().deriveFont(20.0f));

    plot = (XYPlot) jFreeChart.getPlot();

    plot.setBackgroundPaint(ChartHelper.COLOR_PLOT);
    plot.setDomainGridlinePaint(ChartHelper.COLOR_GRIDLINES);
    plot.setRangeGridlinePaint(ChartHelper.COLOR_GRIDLINES);
    plot.setAxisOffset(ChartHelper.PLOT_RECTANGLE_INSETS);

    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(false);

    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(true);

    // Make the Crosshair more visible by changing the width from the default
    strokeCrosshair = new BasicStroke(2.0f, // The width of this BasicStroke
            BasicStroke.CAP_BUTT, // The decoration of the ends of a BasicStroke
            BasicStroke.JOIN_BEVEL, // The decoration applied where path segments meet
            0.0f, // The limit to trim the miter join
            new float[] { 2.0f, 2.0f }, // The array representing the dashing pattern
            0.0f); // The offset to start the dashing pattern
    plot.setDomainCrosshairStroke(strokeCrosshair);
    plot.setRangeCrosshairStroke(strokeCrosshair);

    renderer = new XYDotRenderer();
    renderer.setDotWidth(2);
    renderer.setDotHeight(2);
    plot.setRenderer(renderer);

    axisDomain = (NumberAxis) plot.getDomainAxis();
    axisRange = plot.getRangeAxis();

    // Remember that a GPS Scatter Plot has no ChannelSelector
    if (canAutorange()) {
        // The fix could be anywhere...
        axisDomain.setAutoRangeIncludesZero(false);
        axisDomain.setAutoRange(true);
        axisRange.setAutoRange(true);
    } else {
        // Allow range to full global extents!
        axisDomain.setRange(getLinearFixedMinY(), getLinearFixedMaxY());
        axisRange.setRange(-90.0, 90.0);
    }

    return (jFreeChart);
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java

/***********************************************************************************************
 * Create a simple Chart from the specified XYDataset.
 * Choose a TimeSeriesChart or a XYLineChart appropriately.
 * Called from createCustomisedChart() in each ChartUIComponent subclass.
 *
 *
 * @param dataset//from www  . ja v a 2 s  . co  m
 * @param timezone
 * @param metadatalist
 * @param channelcount
 * @param temperaturechannel
 * @param updatetype
 * @param displaylimit
 * @param channelselector
 * @param debug
 *
 * @return JFreeChart
 */

public static JFreeChart createChart(final XYDataset dataset, final TimeZone timezone,
        final List<Metadata> metadatalist, final int channelcount, final boolean temperaturechannel,
        final DataUpdateType updatetype, final int displaylimit,
        final ChannelSelectorUIComponentInterface channelselector, final boolean debug) {
    final String SOURCE = "ChartHelper.createChart() ";
    final JFreeChart chart;
    final String strTitle;
    final String strLabelX;
    final String strLabelY;
    final XYDataset xyDatasetToDisplay;

    // The set of Metadata available should include the Instrument
    // and any items from the current observation
    strTitle = MetadataHelper.getMetadataValueByKey(metadatalist,
            MetadataDictionary.KEY_OBSERVATION_TITLE.getKey());
    strLabelX = MetadataHelper.getMetadataValueByKey(metadatalist,
            MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_X.getKey());
    // Axis.Y.0 only in this version
    strLabelY = MetadataHelper.getMetadataValueByKey(metadatalist,
            MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ZERO);

    // Transform the XYdataset in accordance with the current ChannelSelection Mode before displaying

    channelselector.debugSelector(debug, SOURCE);

    xyDatasetToDisplay = copyTransformedXYDataset(dataset, timezone, updatetype, displaylimit,
            channelselector.isDecimating(), channelselector.getChannelSelectionModes());
    if (dataset instanceof TimeSeriesCollection) {
        chart = ChartFactory.createTimeSeriesChart(strTitle, strLabelX, strLabelY, xyDatasetToDisplay,
                channelselector.hasLegend(), true, false);
    } else {
        chart = ChartFactory.createXYLineChart(strTitle, strLabelX, strLabelY, xyDatasetToDisplay,
                PlotOrientation.VERTICAL, channelselector.hasLegend(), true, false);
    }

    if ((chart != null) && (chart.getXYPlot() != null) && (chart.getXYPlot().getRangeAxis() != null)) {
        final Stroke strokeCrosshair;
        final XYPlot plot;
        final XYItemRenderer renderer;

        chart.setBackgroundPaint(UIComponentPlugin.DEFAULT_COLOUR_CANVAS.getColor());

        // Experimental chart configuration
        chart.getTitle().setFont(UIComponentPlugin.DEFAULT_FONT.getFont().deriveFont(20.0f));

        plot = chart.getXYPlot();
        plot.setBackgroundPaint(COLOR_PLOT);
        plot.setDomainGridlinePaint(COLOR_GRIDLINES);
        plot.setRangeGridlinePaint(COLOR_GRIDLINES);
        plot.setAxisOffset(PLOT_RECTANGLE_INSETS);

        plot.setDomainCrosshairVisible(true);
        plot.setDomainCrosshairLockedOnData(false);
        plot.setRangeCrosshairVisible(false);

        // Make the Crosshair more visible by changing the width from the default
        strokeCrosshair = new BasicStroke(2.0f, // The width of this BasicStroke
                BasicStroke.CAP_BUTT, // The decoration of the ends of a BasicStroke
                BasicStroke.JOIN_BEVEL, // The decoration applied where path segments meet
                0.0f, // The limit to trim the miter join
                new float[] { 2.0f, 2.0f }, // The array representing the dashing pattern
                0.0f); // The offset to start the dashing pattern
        plot.setDomainCrosshairStroke(strokeCrosshair);

        renderer = plot.getRenderer();

        if ((renderer != null) && (renderer instanceof XYLineAndShapeRenderer)) {
            final XYLineAndShapeRenderer xyItemRenderer;
            int intSeriesCount;

            xyItemRenderer = (XYLineAndShapeRenderer) renderer;

            xyItemRenderer.setBaseLinesVisible(true);
            xyItemRenderer.setBaseShapesVisible(false);
            xyItemRenderer.setBaseShapesFilled(true);
            xyItemRenderer.setItemLabelsVisible(true);

            // Set the shape for the Chart legend items
            ChartUIHelper.setLegendShape(xyItemRenderer);

            // Colour only as many Series as we know about
            intSeriesCount = 0;

            // Examine the state of each channel's selection
            for (int channel = 0; channel < channelcount; channel++) {
                final ChannelSelectionMode selectionMode;

                if ((channelselector.getChannelSelectionModes() != null)
                        && (channelselector.getChannelSelectionModes().size() == channelcount)) {
                    // If there is a ChannelSelector, get the gain setting, or OFF
                    selectionMode = channelselector.getChannelSelectionModes().get(channel);
                } else if (!channelselector.showChannels()) {
                    // If there is no ChannelSelector, we assume that all Channels are ON, at X1
                    selectionMode = ChannelSelectionMode.X1;
                } else {
                    // Not sure what to do, so just show all
                    selectionMode = ChannelSelectionMode.X1;
                }

                if (!ChannelSelectionMode.OFF.equals(selectionMode)) {
                    final ColourInterface colour;

                    colour = MetadataHelper.getChannelColour(metadatalist, channel, temperaturechannel);

                    MetadataHelper.showMetadataList(metadatalist, SOURCE + " COLOURS FOR CHART",
                            LOADER_PROPERTIES.isMetadataDebug());

                    if (colour != null) {
                        // Map the Colour to the Series
                        xyItemRenderer.setSeriesPaint(intSeriesCount, colour.getColor());
                    } else {
                        // Use the default colour if the metadata doesn't have it
                        LOGGER.error(SOURCE
                                + "The channel colour was missing or incorrectly specified in the Metadata, using default colour"
                                + " [channel=" + channel + "]");
                        xyItemRenderer.setSeriesPaint(intSeriesCount,
                                ChartUIHelper.getStandardColour(channel).getColor());
                    }

                    // Prepare for the next Series
                    intSeriesCount++;
                }
            }
        }
    }

    return (chart);
}

From source file:org.webcat.grader.graphs.StackedAreaChart.java

@Override
protected JFreeChart generateChart(WCChartTheme chartTheme) {
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, xAxisLabel(), yAxisLabel(), tableXYDataset(),
            orientation(), true, false, false);

    XYPlot plot = chart.getXYPlot();

    long diff = (long) tableXYDataset().getXValue(0, tableXYDataset().getItemCount() - 1)
            - (long) tableXYDataset().getXValue(0, 0);

    GregorianCalendar calDiff = new GregorianCalendar();
    calDiff.setTime(new NSTimestamp(diff));

    // Set the time axis
    PeriodAxis axis = new PeriodAxis(null); // ( "Date" );
    PeriodAxisLabelInfo labelinfo[] = new PeriodAxisLabelInfo[2];

    if (calDiff.get(Calendar.DAY_OF_YEAR) > 1) {
        axis.setTimeZone(TimeZone.getTimeZone(user().timeZoneName()));
        axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class);
        axis.setMajorTickTimePeriodClass(org.jfree.data.time.Week.class);

        labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d"),
                PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true,
                PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT);

        labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM"),
                PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true,
                PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT);
    } else {/*from  w w w.  j  a  v a  2s  .com*/
        axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Hour.class);

        labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("ha"),
                PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true,
                PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT);

        labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM-d"),
                PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true,
                PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT);
    }

    axis.setLabelInfo(labelinfo);
    plot.setDomainAxis(axis);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    NumberTickUnit tickUnit = new NumberTickUnit(5);
    rangeAxis.setTickUnit(tickUnit);

    XYAreaRenderer2 renderer = (XYAreaRenderer2) plot.getRenderer();
    renderer.setOutline(true);
    renderer.setAutoPopulateSeriesOutlinePaint(true);

    plot.setDomainMinorGridlinesVisible(false);
    plot.setRangeMinorGridlinesVisible(false);

    if (markValue != null) {
        plot.setDomainCrosshairVisible(true);
        plot.setDomainCrosshairValue(markValue.doubleValue());
        plot.setDomainCrosshairPaint(Color.red);
        plot.setDomainCrosshairStroke(MARKER_STROKE);
    }

    chart.getLegend().setBorder(0, 0, 0, 0);

    return chart;
}