Example usage for org.jfree.chart.renderer.category LineAndShapeRenderer setSeriesShape

List of usage examples for org.jfree.chart.renderer.category LineAndShapeRenderer setSeriesShape

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category LineAndShapeRenderer setSeriesShape.

Prototype

public void setSeriesShape(int series, Shape shape) 

Source Link

Document

Sets the shape used for a series and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.pentaho.chart.plugin.jfreechart.chart.line.JFreeLineChartGenerator.java

/**
 * @param categoryPlot/*w ww  .  j  a  v a 2 s. c o  m*/
 * @param seriesElements
 * 
 * Set the line marker attributes
 */
private static void setSeriesMarkerStyles(CategoryPlot categoryPlot, ChartElement[] seriesElements) {
    final int length = seriesElements.length;
    final ShapeFactory shapeFacObj = ShapeFactory.getInstance();
    for (int i = 0; i < length; i++) {
        final ChartElement currElement = seriesElements[i];

        if (categoryPlot.getRenderer() instanceof LineAndShapeRenderer) {
            final LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer();
            lineAndShapeRenderer.setSeriesShapesVisible(i, isMarkerVisible(currElement));
            lineAndShapeRenderer.setSeriesShape(i, shapeFacObj.getShape(currElement));
            lineAndShapeRenderer.setSeriesShapesFilled(i, isShapeFilled(currElement));
        }
    }
}

From source file:org.jfree.chart.demo.LineChartDemo7.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Line Chart Demo 7", "Category", "Count",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setSeriesShapesVisible(0, true);
    lineandshaperenderer.setSeriesShapesVisible(1, false);
    lineandshaperenderer.setSeriesShapesVisible(2, true);
    lineandshaperenderer.setSeriesLinesVisible(2, false);
    lineandshaperenderer.setSeriesShape(2, ShapeUtilities.createDiamond(4F));
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    return jfreechart;
}

From source file:org.jfree.chart.demo.LineChartDemo8.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Line Chart Demo 8", "Category", "Count",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    SymbolAxis symbolaxis = new SymbolAxis("Group", new String[] { "A", "B", "C", "D", "E", "F" });
    categoryplot.setRangeAxis(symbolaxis);
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setSeriesShapesVisible(0, true);
    lineandshaperenderer.setSeriesShapesVisible(1, false);
    lineandshaperenderer.setSeriesShapesVisible(2, true);
    lineandshaperenderer.setSeriesLinesVisible(2, false);
    lineandshaperenderer.setSeriesShape(2, ShapeUtilities.createDiamond(4F));
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    return jfreechart;
}

From source file:sas.BarChart.java

public static JFreeChart createChart(CategoryDataset categorydataset, String name, String type, String t) {
    JFreeChart jfreechart = ChartFactory.createLineChart(name, null, type, categorydataset,
            PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle(t));
    TextTitle texttitle = new TextTitle("");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.CENTER);
    jfreechart.addSubtitle(texttitle);//  www . ja va  2s  .c  om
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setRangePannable(true);
    categoryplot.setRangeGridlinesVisible(false);
    java.net.URL url = (BarChart.class).getClassLoader().getResource("line_Chart_example.png");
    if (url != null) {
        ImageIcon imageicon = new ImageIcon(url);
        jfreechart.setBackgroundImage(imageicon.getImage());
        categoryplot.setBackgroundPaint(null);
    }
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ChartUtilities.applyCurrentTheme(jfreechart);
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F));
    lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F));
    lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    return jfreechart;
}

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

/**
 * Decorate the benford law chart. in this method the line chart will be overlay on top of bar chart.
 * /* ww w . jav  a2 s. c o  m*/
 * @param dataset
 * @param barChart
 * @param title
 * @param categoryAxisLabel
 * @param dotChartLabels
 * @param formalValues
 * @return JFreeChart
 */
@SuppressWarnings("deprecation")
public static JFreeChart decorateBenfordLawChartByKCD(CategoryDataset dataset, Object customerDataset,
        JFreeChart barChart, String title, String categoryAxisLabel, List<String> dotChartLabels,
        double[] formalValues) {
    CategoryPlot barplot = barChart.getCategoryPlot();
    decorateBarChart(barChart, new BenfordLawLineAndShapeRenderer());
    // display percentage on top of the bar
    DecimalFormat df = new DecimalFormat(PERCENT_FORMAT);
    barplot.getRenderer().setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", df)); //$NON-NLS-1$
    barplot.getRenderer().setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
    // set the display of Y axis
    NumberAxis numAxis = (NumberAxis) barplot.getRangeAxis();
    numAxis.setNumberFormatOverride(df);

    CategoryDataset lineDataset = getLineDataset(dotChartLabels, formalValues);
    JFreeChart lineChart = ChartFactory.createLineChart(null, title, categoryAxisLabel, lineDataset,
            PlotOrientation.VERTICAL, false, false, false);
    CategoryPlot plot = lineChart.getCategoryPlot();
    if (customerDataset != null) {
        barplot.setDataset(2, new EncapsulationCumstomerDataset(dataset, customerDataset));
    }
    // show the value on the right axis of the chart(keep the comment)
    // NumberAxis numberaxis = new NumberAxis(DefaultMessagesImpl.getString("TopChartFactory.Value"));
    // plot.setRangeAxis(10, numberaxis);

    NumberAxis vn = (NumberAxis) plot.getRangeAxis();
    vn.setNumberFormatOverride(df);
    // set points format
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setPaint(COLOR_LIST.get(1));
    renderer.setSeriesShape(1, new Rectangle2D.Double(-1.5, -1.5, 3, 3));
    renderer.setShapesVisible(true); // show the point shape
    renderer.setBaseLinesVisible(false);// do not show the line

    // add the bar chart into the line chart
    CategoryItemRenderer barChartRender = barplot.getRenderer();
    barplot.setDataset(0, lineDataset);
    barplot.setRenderer(0, plot.getRenderer());
    barplot.setDataset(1, dataset);
    barplot.setRenderer(1, barChartRender);
    return barChart;
}

From source file:org.apache.qpid.disttest.charting.chartbuilder.CategoryStrokeAndPaintApplier.java

@Override
public void setSeriesShape(final int seriesIndex, final java.awt.Shape shape, final JFreeChart targetChart) {
    CategoryItemRenderer renderer = targetChart.getCategoryPlot().getRenderer();
    if (renderer instanceof LineAndShapeRenderer) {
        LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) renderer;
        lineAndShapeRenderer.setSeriesShapesVisible(seriesIndex, true);
        lineAndShapeRenderer.setSeriesShape(seriesIndex, shape);
    }// ww  w.  j  a va2 s  . c om
}

From source file:virgil.meanback.HistoryInfo.java

public void printChart(Stock stock, List<String[]> list, int days) throws Exception {
    //?/* w  w w  . j a v a  2s.c  o m*/
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //
    standardChartTheme.setRegularFont(new Font("", Font.BOLD, 12));
    //?
    standardChartTheme.setLargeFont(new Font("", Font.BOLD, 18));
    //?
    ChartFactory.setChartTheme(standardChartTheme);
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    for (int i = list.size() - 1; i >= 0; i--) {
        String[] s = (String[]) list.get(i);
        dataSet.addValue(Double.parseDouble(s[1]), days + "", s[0]);
        dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "", s[0]);
        float sub = Float.parseFloat(s[2]);
        float error = Float.parseFloat(s[3]);
        if (sub > error * 2) {
            dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "??", s[0]);
        }
    }

    //?????Legend
    //????
    //??URL
    JFreeChart chart = ChartFactory.createLineChart(
            stock.getName() + "(" + stock.getCode() + ") ", "", "", dataSet,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot cp = chart.getCategoryPlot();
    cp.setBackgroundPaint(ChartColor.WHITE); // 
    CategoryAxis categoryAxis = cp.getDomainAxis();
    //  Lable 90 
    Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 10);
    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    categoryAxis.setTickLabelFont(labelFont);//X?? 
    ValueAxis yAxis = cp.getRangeAxis();
    yAxis.setAutoRange(true);
    double[] d = getAxiasThresold(stock, list);
    yAxis.setLowerBound(d[0] - 0.15);
    yAxis.setUpperBound(d[1] + 0.15);
    LineAndShapeRenderer lasp = (LineAndShapeRenderer) cp.getRenderer();
    lasp.setBaseFillPaint(ChartColor.RED);
    lasp.setDrawOutlines(true);
    lasp.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) cp.getRenderer(1);//?
    DecimalFormat decimalformat1 = new DecimalFormat("##.##");//???
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
    //????
    renderer.setItemLabelsVisible(true);//
    renderer.setBaseItemLabelsVisible(true);//
    //?????
    renderer.setShapesFilled(Boolean.TRUE);//??
    renderer.setShapesVisible(true);//?
    ChartFrame chartFrame = new ChartFrame("??", chart, true);
    //chart?JavaChartFramejavaJframe????
    chartFrame.pack(); //??
    chartFrame.setVisible(true);//???
}

From source file:gg.view.categoriesbalances.GraphCategoriesBalancesTopComponent.java

/**
 * Displays the categories/sub-categories' balances by period
 * @param balances Categories' balances//from w  ww .j  av a 2  s  .c  o  m
 */
private void displayData(Map<Long, Map<SearchCriteria, BigDecimal>> balances) {
    log.info("Categories' balances graph computed and displayed");

    // Display hourglass cursor
    Utilities.changeCursorWaitStatus(true);

    // Create the dataset (that will contain the categories/sub-categories' balances)
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Create an empty chart
    JFreeChart chart = ChartFactory.createLineChart("", // chart title
            "", // x axis label
            NbBundle.getMessage(GraphCategoriesBalancesTopComponent.class,
                    "GraphAccountsBalancesTopComponent.Amount"), // y axis label
            dataset, // data displayed in the chart
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // Chart color
    chart.setBackgroundPaint(jPanelCategoriesBalances.getBackground());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    // Grid lines
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // Set the orientation of the categories on the domain axis (X axis)
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // Add the series on the chart for each category/sub-category displayed in the table
    for (Long categoryId : balances.keySet()) {
        Category category = Wallet.getInstance().getCategoriesWithId().get(categoryId);
        assert (category != null);

        SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>(
                balances.get(categoryId).keySet());
        for (SearchCriteria searchCriteria : sortedSearchCriteria) {

            if ((!searchCriteria.hasCategoriesFilter() && category.isTopCategory()
                    && !category.getSystemProperty()) || searchCriteria.getCategories().contains(category)) {

                BigDecimal balance = new BigDecimal(0);
                if (balances.get(categoryId) != null && balances.get(categoryId).get(searchCriteria) != null) {
                    balance = balances.get(categoryId).get(searchCriteria);
                }

                dataset.addValue(balance, category.getName(), searchCriteria.getPeriod());
            }
        }
    }

    // Series' shapes
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    for (int i = 0; i < dataset.getRowCount(); i++) {
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F));
    }
    // Set the scale of the chart
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Create the chart panel that contains the chart
    ChartPanel chartPanel = new ChartPanel(chart);

    // Display the chart
    jPanelCategoriesBalances.removeAll();
    jPanelCategoriesBalances.add(chartPanel, BorderLayout.CENTER);
    jPanelCategoriesBalances.updateUI();

    // Display normal cursor
    Utilities.changeCursorWaitStatus(false);
}

From source file:gg.view.accountsbalances.GraphAccountsBalancesTopComponent.java

/**
 * Displays the accounts' balances by period
 * @param balances Accounts' balances/*  ww  w.j  a  va  2s  .c  om*/
 */
private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) {
    log.info("Accounts' balances graph computed and displayed");

    // Display hourglass cursor
    Utilities.changeCursorWaitStatus(true);

    // Create the dataset (that will contain the accounts' balances)
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Create an empty chart
    JFreeChart chart = ChartFactory.createLineChart("", // chart title
            "", // x axis label
            NbBundle.getMessage(GraphAccountsBalancesTopComponent.class, "AccountsBalancesTopComponent.Amount"), // y axis label
            dataset, // data displayed in the chart
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // Chart color
    chart.setBackgroundPaint(jPanelAccountsBalances.getBackground());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    // Grid lines
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // Set the orientation of the categories on the domain axis (X axis)
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // Add the series on the chart for each account displayed in the table
    for (MoneyContainer moneyContainer : balances.keySet()) {

        if (moneyContainer instanceof Account) {
            Account account = (Account) moneyContainer;
            SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>(
                    balances.get(account).keySet());

            for (SearchCriteria searchCriteria : sortedSearchCriteria) {
                if (!searchCriteria.hasAccountsFilter() || searchCriteria.getAccounts().contains(account)) {

                    dataset.addValue(balances.get(moneyContainer).get(searchCriteria), account.toString(),
                            searchCriteria.getPeriod());
                }
            }
        }
    }

    // Series' shapes
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    for (int i = 0; i < dataset.getRowCount(); i++) {
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F));
    }
    // Set the scale of the chart
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Create the chart panel that contains the chart
    ChartPanel chartPanel = new ChartPanel(chart);

    // Display the chart
    jPanelAccountsBalances.removeAll();
    jPanelAccountsBalances.add(chartPanel, BorderLayout.CENTER);
    jPanelAccountsBalances.updateUI();

    // Display normal cursor
    Utilities.changeCursorWaitStatus(false);
}

From source file:gg.view.movementsbalances.GraphMovementsBalancesTopComponent.java

/**
 * Displays the accounts' movements balances by period
 * @param searchFilters Search filter objects (one per period) for which the movements balances are wanted
 *///from   w ww.j  ava  2s .co  m
private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) {
    log.info("Movements' balances graph computed and displayed");

    // Display hourglass cursor
    Utilities.changeCursorWaitStatus(true);

    // Create the dataset (that will contain the movements' balances)
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Create an empty chart
    JFreeChart chart = ChartFactory.createLineChart("", // chart title
            "", // x axis label
            NbBundle.getMessage(GraphMovementsBalancesTopComponent.class,
                    "GraphMovementsBalancesTopComponent.Amount"), // y axis label
            dataset, // data displayed in the chart
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // Chart color
    chart.setBackgroundPaint(jPanelMovementsBalances.getBackground());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    // Grid lines
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // Set the orientation of the categories on the domain axis (X axis)
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // Add the series on the chart
    for (MoneyContainer moneyContainer : balances.keySet()) {
        if (moneyContainer instanceof Account) {

            SortedSet<SearchCriteria> sortedSearchFilters = new TreeSet<SearchCriteria>(
                    balances.get(moneyContainer).keySet());

            for (SearchCriteria searchCriteria : sortedSearchFilters) {
                BigDecimal accountBalance = balances.get(moneyContainer).get(searchCriteria);
                accountBalance = accountBalance.setScale(2, RoundingMode.HALF_EVEN);

                dataset.addValue(accountBalance, moneyContainer.toString(), searchCriteria.getPeriod());
            }
        }
    }

    // Series' shapes
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    for (int i = 0; i < dataset.getRowCount(); i++) {
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F));
    }

    // Set the scale of the chart
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(true);
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Create the chart panel that contains the chart
    ChartPanel chartPanel = new ChartPanel(chart);

    // Display the chart
    jPanelMovementsBalances.removeAll();
    jPanelMovementsBalances.add(chartPanel, BorderLayout.CENTER);
    jPanelMovementsBalances.updateUI();

    // Display normal cursor
    Utilities.changeCursorWaitStatus(false);
}