Example usage for org.jfree.chart.title LegendTitle setItemFont

List of usage examples for org.jfree.chart.title LegendTitle setItemFont

Introduction

In this page you can find the example usage for org.jfree.chart.title LegendTitle setItemFont.

Prototype

public void setItemFont(Font font) 

Source Link

Document

Sets the item font and sends a TitleChangeEvent to all registered listeners.

Usage

From source file:com.manydesigns.portofino.chart.ChartStackedBarGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);/*from  www. j  ava  2s . c o m*/
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper x = new ComparableWrapper((Comparable) current[0]);
        ComparableWrapper y = new ComparableWrapper((Comparable) current[1]);
        if (current.length > 3) {
            x.setLabel(current[3].toString());
        }
        if (current.length > 4) {
            y.setLabel(current[4].toString());
        }
        dataset.setValue((Number) current[2], x, y);
    }

    PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL;
    if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) {
        plotOrientation = PlotOrientation.VERTICAL;
    }

    JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation);

    chart.setAntiAlias(antiAlias);

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(borderVisible);

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryItemRenderer renderer = plot.getRenderer();
    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression());
        renderer.setBaseItemURLGenerator(urlGenerator);
    } else {
        renderer.setBaseItemURLGenerator(null);
    }
    renderer.setBaseOutlinePaint(Color.BLACK);

    // ///////////////
    if (renderer instanceof BarRenderer) {
        BarRenderer barRenderer = (BarRenderer) renderer;

        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());

        // hongliangpan add
        // ?
        barRenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
        // bar???
        barRenderer.setMinimumBarLength(0.02);
        // 
        barRenderer.setMaximumBarWidth(0.06);
    }
    if (renderer instanceof StackedBarRenderer3D || renderer instanceof StackedBarRenderer) {
        BarRenderer barRenderer = (BarRenderer) renderer;
        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());

        // hongliangpan add
        // ? setSeriesItemLabelGenerator
        barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        // bar???
        barRenderer.setMinimumBarLength(0.02);
        // 
        barRenderer.setMaximumBarWidth(0.06);
        // ?????
        ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D);
        // ??labelposition
        barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback);
        barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback);

        barRenderer.setItemLabelsVisible(true);
        barRenderer.setItemMargin(10);
    }

    // ///////////////

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})"));

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // Category axis
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setAxisLinePaint(Color.BLACK);
    categoryAxis.setLabelFont(axisFont);
    categoryAxis.setAxisLineVisible(true);

    // impostiamo la rotazione dell'etichetta
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT,
                TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0,
                CategoryLabelWidthType.CATEGORY, 100);
        CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos);
        categoryAxis.setCategoryLabelPositions(positions);
        categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f);
        height = 333;
    } else {
        categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f);

        // recuperiamo 8 pixel a sinistra
        plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0));

        height = 74;

        // contiamo gli elementi nel dataset
        height += 23 * dataset.getColumnCount();

        height += 57;
    }

    Axis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAxisLinePaint(Color.BLACK);
    rangeAxis.setLabelFont(axisFont);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);

    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:jmemorize.gui.swing.panels.DeckChartPanel.java

private JFreeChart createChart() {
    m_dataset = createDefaultDataSet();//  w w  w  .  j a  v a 2 s .c o  m

    JFreeChart chart = ChartFactory.createStackedBarChart3D(null, // chart title
            null, // domain axis label
            Localization.get("DeckChart.CARDS"), // range axis label //$NON-NLS-1$
            m_dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    // setup legend
    // TODO we used to do this for the old jfreechar version, but it's not clear why.
    // can we get rid of it?
    LegendTitle legend = chart.getLegend();
    //        legend.setsetRenderingOrder(LegendRenderingOrder.REVERSE);
    legend.setItemFont(legend.getItemFont().deriveFont(11f));

    // setup plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    TickUnitSource tickUnits = NumberAxis.createIntegerTickUnits();
    plot.getRangeAxis().setStandardTickUnits(tickUnits); //CHECK use locale
    plot.setForegroundAlpha(0.99f);

    // setup renderer
    m_barRenderer = new MyBarRenderer();
    m_barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    m_barRenderer.setItemLabelsVisible(true);
    m_barRenderer
            .setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    plot.setRenderer(m_barRenderer);
    setSeriesPaint();

    return chart;
}

From source file:com.ikon.servlet.admin.StatsGraphServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String action = WebUtils.getString(request, "action", "graph");
    String type = WebUtils.getString(request, "t");
    JFreeChart chart = null;// w  w w  .ja v a 2 s. c  o m
    updateSessionManager(request);

    try {
        if ("refresh".equals(action)) {
            new RepositoryInfo().runAs(null);
            ServletContext sc = getServletContext();
            sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response);
        } else {
            response.setContentType("image/png");
            OutputStream out = response.getOutputStream();

            if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) {
                chart = repoStats(type);
            } else if (DISK.equals(type)) {
                chart = diskStats();
            } else if (JVM_MEMORY.equals(type)) {
                chart = jvmMemStats();
            } else if (OS_MEMORY.equals(type)) {
                chart = osMemStats();
            }

            if (chart != null) {
                // Customize title font
                chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16));

                // Match body {   background-color:#F6F6EE; }
                chart.setBackgroundPaint(new Color(246, 246, 238));

                // Customize no data
                PiePlot plot = (PiePlot) chart.getPlot();
                plot.setNoDataMessage("No data to display");

                // Customize labels
                plot.setLabelGenerator(null);

                // Customize legend
                LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
                legend.setPosition(RectangleEdge.BOTTOM);
                legend.setFrame(BlockBorder.NONE);
                legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12));
                chart.removeLegend();
                chart.addLegend(legend);

                if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) {
                    ChartUtilities.writeChartAsPNG(out, chart, 225, 225);
                } else {
                    ChartUtilities.writeChartAsPNG(out, chart, 250, 250);
                }
            }

            out.flush();
            out.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.rapidminer.gui.viewer.ROCChartPlotter.java

private JFreeChart createChart(XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from   w  ww . jav a 2 s . c om*/

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
    valueAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLabelFont(PlotterAdapter.LABEL_FONT_BOLD);
    domainAxis.setTickLabelFont(PlotterAdapter.LABEL_FONT);

    DeviationRenderer renderer = new DeviationRenderer(true, false);
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    if (dataset.getSeriesCount() == 1) {
        renderer.setSeriesStroke(0, stroke);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesFillPaint(0, Color.RED);
    } else if (dataset.getSeriesCount() == 2) {
        renderer.setSeriesStroke(0, stroke);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesFillPaint(0, Color.RED);

        renderer.setSeriesStroke(1, stroke);
        renderer.setSeriesPaint(1, Color.BLUE);
        renderer.setSeriesFillPaint(1, Color.BLUE);
    } else {
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesStroke(i, stroke);
            Color color = colorProvider.getPointColor((double) i / (double) (dataset.getSeriesCount() - 1));
            renderer.setSeriesPaint(i, color);
            renderer.setSeriesFillPaint(i, color);
        }
    }
    renderer.setAlpha(0.12f);
    plot.setRenderer(renderer);

    // legend settings
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setPosition(RectangleEdge.TOP);
        legend.setFrame(BlockBorder.NONE);
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        legend.setItemFont(PlotterAdapter.LABEL_FONT);
    }
    return chart;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.MultiPieChartExpression.java

protected void configureSubChart(final JFreeChart chart) {
    final TextTitle chartTitle = chart.getTitle();
    if (chartTitle != null) {
        if (getPieTitleFont() != null) {
            chartTitle.setFont(getPieTitleFont());
        } else {/* w ww .  j  a v  a 2  s. co  m*/
            final Font titleFont = Font.decode(getTitleFont());
            chartTitle.setFont(titleFont);
        }
    }

    if (isAntiAlias() == false) {
        chart.setAntiAlias(false);
    }

    final LegendTitle chLegend = chart.getLegend();
    if (chLegend != null) {
        final RectangleEdge loc = translateEdge(getLegendLocation().toLowerCase());
        if (loc != null) {
            chLegend.setPosition(loc);
        }
        if (getLegendFont() != null) {
            chLegend.setItemFont(Font.decode(getLegendFont()));
        }
        if (!isDrawLegendBorder()) {
            chLegend.setBorder(BlockBorder.NONE);
        }
        if (getLegendBackgroundColor() != null) {
            chLegend.setBackgroundPaint(getLegendBackgroundColor());
        }
        if (getLegendTextColor() != null) {
            chLegend.setItemPaint(getLegendTextColor());
        }
    }

    final Plot plot = chart.getPlot();
    plot.setNoDataMessageFont(Font.decode(getLabelFont()));

    final String pieNoData = getPieNoDataMessage();
    if (pieNoData != null) {
        plot.setNoDataMessage(pieNoData);
    } else {
        final String message = getNoDataMessage();
        if (message != null) {
            plot.setNoDataMessage(message);
        }
    }
}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * /* w w  w.  j  ava 2 s . c  o  m*/
 * if it contians CJK, set Font to "Arial Unicode MS".Or else, the Font is "Tahoma".
 * 
 * @param chart
 */
private static void setLegendFont(JFreeChart chart) {
    Font font;
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE);//$NON-NLS-1$
        // get legend label to judge if it contains CJK.
        LegendItemSource[] sources = legend.getSources();
        Set<String> itemLabels = new HashSet<String>();
        for (LegendItemSource source : sources) {
            LegendItemCollection legendItems = source.getLegendItems();
            for (int i = 0; i < legendItems.getItemCount(); i++) {
                String label = legendItems.get(i).getLabel();
                if (label != null) {
                    itemLabels.add(label);
                }
            }
        }
        if (isContainCJKCharacter(itemLabels.toArray())) {
            font = getCJKFont(Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
        }
        legend.setItemFont(font);
    }
}

From source file:com.rapidminer.gui.plotter.charts.DeviationChartPlotter.java

@Override
public void updatePlotter() {
    int categoryCount = prepareData();
    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {/*w w  w  . j  av a 2s  . c om*/
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Deviation plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
        // LogService.WARNING);
        LogService.getRoot().log(Level.WARNING,
                "com.rapidminer.gui.plotter.charts.DeviationChartPlotter.parsing_property_error");
    }
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

    JFreeChart chart = createChart(this.dataset, createLegend);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // domain axis
    SymbolAxis axis = null;
    if (this.dataTable.isSupportingColumnWeights()) {
        List<Double> weightList = new LinkedList<Double>();
        for (int column = 0; column < dataTable.getNumberOfColumns(); column++) {
            if (!dataTable.isSpecial(column) && column != colorColumn) {
                weightList.add(this.dataTable.getColumnWeight(column));
            }
        }
        double[] weights = new double[weightList.size()];
        int index = 0;
        for (Double d : weightList) {
            weights[index++] = d;
        }
        axis = new WeightBasedSymbolAxis(null, domainAxisMap, weights);
    } else {
        axis = new SymbolAxis(null, domainAxisMap);
    }
    axis.setTickLabelFont(LABEL_FONT);
    axis.setLabelFont(LABEL_FONT_BOLD);

    // rotate labels
    if (isLabelRotating()) {
        axis.setTickLabelsVisible(true);
        axis.setVerticalTickLabels(true);
    }

    chart.getXYPlot().setDomainAxis(axis);

    // legend settings
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setPosition(RectangleEdge.TOP);
        legend.setFrame(BlockBorder.NONE);
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        legend.setItemFont(LABEL_FONT);
    }

    if (panel instanceof AbstractChartPanel) {
        panel.setChart(chart);
    } else {
        panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
        final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
        panel.addMouseListener(controller);
        panel.addMouseMotionListener(controller);
    }

    // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
    panel.getChartRenderingInfo().setEntityCollection(null);
}

From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/** init the legend */
private final void __initLegend() {
    final LegendTitle t;

    if (this.getLegendType() != ELegendType.NO_LEGEND) {
        t = new LegendTitle(this.m_plot);
        t.setItemFont(this.getDriver().getPalette().getLegendFont());
        t.setBackgroundPaint(this.getDriver().getPalette().getBackgroundColor());
        t.setVisible(true);/*  w  w w. ja  v  a2 s  . c  o  m*/
        this.m_chart.addLegend(t);
    }
}

From source file:net.sf.mzmine.modules.visualization.tic.TICPlot.java

public TICPlot(final ActionListener listener) {

    super(null, true);

    // Initialize.
    visualizer = listener;/*  www.j a  v  a 2  s .  c  om*/
    labelsVisible = 1;
    havePeakLabels = false;
    numOfDataSets = 0;
    numOfPeaks = 0;
    showSpectrumRequest = false;

    // Set cursor.
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    // Y-axis label.
    final String yAxisLabel;
    if (listener instanceof TICVisualizerWindow) {

        yAxisLabel = ((TICVisualizerWindow) listener).getPlotType() == PlotType.BASEPEAK ? "Base peak intensity"
                : "Total ion intensity";
    } else {

        yAxisLabel = "Base peak intensity";
    }

    // Initialize the chart by default time series chart from factory.
    final JFreeChart chart = ChartFactory.createXYLineChart("", // title
            "Retention time", // x-axis label
            yAxisLabel, // y-axis label
            null, // data set
            PlotOrientation.VERTICAL, // orientation
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // Title.
    chartTitle = chart.getTitle();
    chartTitle.setFont(TITLE_FONT);
    chartTitle.setMargin(TITLE_TOP_MARGIN, 0.0, 0.0, 0.0);

    // Subtitle.
    chartSubTitle = new TextTitle();
    chartSubTitle.setFont(SUBTITLE_FONT);
    chartSubTitle.setMargin(TITLE_TOP_MARGIN, 0.0, 0.0, 0.0);
    chart.addSubtitle(chartSubTitle);

    // Disable maximum size (we don't want scaling).
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);

    // Legend constructed by ChartFactory.
    final LegendTitle legend = chart.getLegend();
    legend.setItemFont(LEGEND_FONT);
    legend.setFrame(BlockBorder.NONE);

    // Set the plot properties.
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(AXIS_OFFSET);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // Set grid properties.
    plot.setDomainGridlinePaint(GRID_COLOR);
    plot.setRangeGridlinePaint(GRID_COLOR);

    // Set cross-hair (selection) properties.
    if (listener instanceof TICVisualizerWindow) {

        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        plot.setDomainCrosshairPaint(CROSS_HAIR_COLOR);
        plot.setRangeCrosshairPaint(CROSS_HAIR_COLOR);
        plot.setDomainCrosshairStroke(CROSS_HAIR_STROKE);
        plot.setRangeCrosshairStroke(CROSS_HAIR_STROKE);
    }

    // Set the x-axis (retention time) properties.
    final NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setNumberFormatOverride(MZmineCore.getConfiguration().getRTFormat());
    xAxis.setUpperMargin(AXIS_MARGINS);
    xAxis.setLowerMargin(AXIS_MARGINS);

    // Set the y-axis (intensity) properties.
    final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat());

    // Set default renderer properties.
    defaultRenderer = new TICPlotRenderer();
    defaultRenderer.setBaseShapesFilled(true);
    defaultRenderer.setDrawOutlines(false);
    defaultRenderer.setUseFillPaint(true);
    defaultRenderer.setBaseItemLabelPaint(LABEL_COLOR);

    // Set label generator
    final XYItemLabelGenerator labelGenerator = new TICItemLabelGenerator(this);
    defaultRenderer.setBaseItemLabelGenerator(labelGenerator);
    defaultRenderer.setBaseItemLabelsVisible(true);

    // Set toolTipGenerator
    final XYToolTipGenerator toolTipGenerator = new TICToolTipGenerator();
    defaultRenderer.setBaseToolTipGenerator(toolTipGenerator);

    // Set focus state to receive key events.
    setFocusable(true);

    // Register key handlers.
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("LEFT"), listener, "MOVE_CURSOR_LEFT");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("RIGHT"), listener, "MOVE_CURSOR_RIGHT");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("SPACE"), listener, "SHOW_SPECTRUM");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke('+'), this, "ZOOM_IN");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke('-'), this, "ZOOM_OUT");

    // Add items to popup menu.
    final JPopupMenu popupMenu = getPopupMenu();
    popupMenu.addSeparator();

    if (listener instanceof TICVisualizerWindow) {

        popupMenu.add(new ExportPopUpMenu((TICVisualizerWindow) listener));
        popupMenu.addSeparator();
        popupMenu.add(new AddFilePopupMenu((TICVisualizerWindow) listener));
        popupMenu.add(new RemoveFilePopupMenu((TICVisualizerWindow) listener));
        popupMenu.add(new ExportPopUpMenu((TICVisualizerWindow) listener));
        popupMenu.addSeparator();
    }

    GUIUtils.addMenuItem(popupMenu, "Toggle showing peak values", this, "SHOW_ANNOTATIONS");
    GUIUtils.addMenuItem(popupMenu, "Toggle showing data points", this, "SHOW_DATA_POINTS");

    if (listener instanceof TICVisualizerWindow) {
        popupMenu.addSeparator();
        GUIUtils.addMenuItem(popupMenu, "Show spectrum of selected scan", listener, "SHOW_SPECTRUM");
    }

    popupMenu.addSeparator();

    GUIUtils.addMenuItem(popupMenu, "Set axes range", this, "SETUP_AXES");

    if (listener instanceof TICVisualizerWindow) {

        GUIUtils.addMenuItem(popupMenu, "Set same range to all windows", this, "SET_SAME_RANGE");
    }
}

From source file:com.rapidminer.gui.plotter.charts.ParallelPlotter2.java

@Override
public void updatePlotter() {
    prepareData();/*from w ww  .  ja v a  2  s.c om*/

    JFreeChart chart = createChart(this.dataset);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // general plot settings
    XYPlot plot = chart.getXYPlot();
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis
    SymbolAxis axis = null;
    if (this.dataTable.isSupportingColumnWeights()) {
        List<Double> weightList = new LinkedList<>();
        for (int column = 0; column < dataTable.getNumberOfColumns(); column++) {
            if ((!dataTable.isSpecial(column)) && (column != colorColumn)) {
                weightList.add(this.dataTable.getColumnWeight(column));
            }
        }
        double[] weights = new double[weightList.size()];
        int index = 0;
        for (Double d : weightList) {
            weights[index++] = d;
        }
        axis = new WeightBasedSymbolAxis(null, domainAxisMap, weights);
    } else {
        axis = new SymbolAxis(null, domainAxisMap);
    }
    axis.setTickLabelFont(LABEL_FONT);
    axis.setLabelFont(LABEL_FONT_BOLD);

    // rotate labels
    if (isLabelRotating()) {
        axis.setTickLabelsVisible(true);
        axis.setVerticalTickLabels(true);
    }

    chart.getXYPlot().setDomainAxis(axis);

    // renderer
    final ColorizedLineAndShapeRenderer renderer = new ColorizedLineAndShapeRenderer(this.colorMap);
    plot.setRenderer(renderer);

    // legend settings
    if ((colorColumn >= 0) && (this.dataTable.isNominal(colorColumn))) {
        final LegendItemCollection legendItemCollection = new LegendItemCollection();
        for (int i = 0; i < this.dataTable.getNumberOfValues(colorColumn); i++) {
            legendItemCollection.add(new LegendItem(this.dataTable.mapIndex(colorColumn, i), null, null, null,
                    new Rectangle2D.Double(0, 0, 7, 7),
                    getColorProvider()
                            .getPointColor(i / (double) (this.dataTable.getNumberOfValues(colorColumn) - 1)),
                    new BasicStroke(0.75f), Color.GRAY));
        }
        chart.addLegend(new LegendTitle(new LegendItemSource() {

            @Override
            public LegendItemCollection getLegendItems() {
                return legendItemCollection;
            }
        }));

        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            legend.setItemFont(LABEL_FONT);
        }
    } else if (colorColumn >= 0) {
        chart.addLegend(new LegendTitle(new LegendItemSource() {

            @Override
            public LegendItemCollection getLegendItems() {
                LegendItemCollection itemCollection = new LegendItemCollection();
                itemCollection.add(new LegendItem("Dummy"));
                return itemCollection;
            }
        }) {

            private static final long serialVersionUID = 1288380309936848376L;

            @Override
            public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area,
                    java.lang.Object params) {
                if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn)
                        || dataTable.isDateTime(colorColumn)) {
                    drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7),
                            dataTable, colorColumn, renderer.getMinColorValue(), renderer.getMaxColorValue());
                    return new BlockResult();
                } else {
                    final String minColorString = Tools.formatNumber(renderer.getMinColorValue());
                    final String maxColorString = Tools.formatNumber(renderer.getMaxColorValue());
                    drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 90), (int) (area.getCenterY() + 7),
                            dataTable.getColumnName(colorColumn), minColorString, maxColorString);
                    return new BlockResult();
                }
            }

            @Override
            public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) {
                draw(g2, area, null);
            }

        });
    }

    // chart panel
    if (panel instanceof AbstractChartPanel) {
        panel.setChart(chart);
    } else {
        panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
        final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
        panel.addMouseListener(controller);
        panel.addMouseMotionListener(controller);
    }

    // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
    panel.getChartRenderingInfo().setEntityCollection(null);
}