Example usage for org.jfree.chart.title TextTitle TextTitle

List of usage examples for org.jfree.chart.title TextTitle TextTitle

Introduction

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

Prototype

public TextTitle(String text) 

Source Link

Document

Creates a new title, using default attributes where necessary.

Usage

From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHelper.java

public static void setChartTitle(JFreeChart chart, RenderableDataItem title) {
    if (title == null) {
        return;// w w  w.j  a v a 2  s. c o  m
    }

    TextTitle tt = new TextTitle(title.toString());

    if (title.getFont() != null) {
        tt.setFont(title.getFont());
    }

    if (title.getForeground() != null) {
        tt.setPaint(title.getForeground());
    }

    switch (title.getIconPosition()) {
    case TOP_CENTER:
        tt.setPosition(RectangleEdge.TOP);

        break;

    case RIGHT:
        tt.setPosition(RectangleEdge.RIGHT);

        break;

    case BOTTOM_CENTER:
        tt.setPosition(RectangleEdge.BOTTOM);

        break;

    case LEFT:
        tt.setPosition(RectangleEdge.LEFT);

        break;

    default:
        break;
    }

    chart.setTitle(tt);
}

From source file:CGgui.java

public CGgui() {
    //main window frame
    f.setResizable(false);/* ww  w  . jav a  2  s. c  om*/
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(fCenter, BorderLayout.CENTER);
    f.getContentPane().add(fEast, BorderLayout.EAST);

    //menu
    mnuFile.add(mnuLoad);
    mnuLoad.add(mnuItemOpenFasta);
    mnuLoad.add(mnuItemOpenBed);
    mnuFile.add(mnuSaveData);
    mnuSaveData.add(mnuItemSavePositions);
    mnuSaveData.add(mnuItemSaveClusters);

    //mnuFile.add(mnuItemOpenDataFile);
    mnuFile.add(mnuSaveCharts);
    mnuSaveCharts.add(mnuItemSaveChrt);
    mnuSaveCharts.add(mnuItemSaveMinChrt);
    mnuSaveCharts.add(mnuItemSaveClusterChrt);
    mnuSaveCharts.add(mnuItemSaveGrayChrt);
    mnuSaveCharts.add(mnuItemSaveGrayMinChrt);
    mnuSaveCharts.add(mnuItemSaveGrayClusterChrt);
    mnuFile.add(mnuItemClearData);
    mnuFile.add(mnuItemQuit);
    mnuEdit.add(mnuItemChartProps);
    mnuEdit.add(mnuItemMinimaProps);
    mnuEdit.add(mnuItemClusterProps);
    mnuEdit.add(mnuItemFindMin);
    mnuEdit.add(mnuItemSetAxes);
    mnuEdit.add(mnuItemShowGrid);
    //   mnuHelp.add(mnuItemMan);
    //   mnuHelp.add(mnuItemAbout);
    mb.add(mnuFile);
    mb.add(mnuEdit);
    //   mb.add(mnuHelp);
    f.setJMenuBar(mb);

    //progressbar
    jprogressbar.setVisible(false);
    jprogressbar.setBorderPainted(false);
    f.getContentPane().add(jprogressbar, BorderLayout.SOUTH);

    //chart area
    //histogram
    ChartArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    chart = ChartFactory.createXYAreaChart("Fragment Length Histogram", "Fragment Length (l)", "Frequency f(l)",
            histogramdataset, PlotOrientation.VERTICAL, true, true, false);
    chart.addSubtitle(0, new TextTitle("n = " + CurrCG));
    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setForegroundAlpha(0.85F);
    xyplot.setDomainCrosshairVisible(false);
    chartpanel = new ChartPanel(chart);
    ChartArea.add("Fragment Length", chartpanel);

    //minima
    minchart = ChartFactory.createXYLineChart("Local Minima", "Fragment Length (l)",
            "Number of Matches per Fragment", minimadataset, PlotOrientation.VERTICAL, true, true, false);
    XYPlot minxyplot = (XYPlot) minchart.getPlot();
    minxyplot.setForegroundAlpha(0.85F);
    minchartpanel = new ChartPanel(minchart);
    ChartArea.add("Minima", minchartpanel);

    //optimization
    clusterchart = ChartFactory.createScatterPlot("Average Cluster Size vs. Maximum Fragment Length",
            "Number (n) of Matches per Fragment",
            "Number of Overlapping Fragments per Cluster/Max Fragment Length", clusterdataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot clusterplot = (XYPlot) clusterchart.getPlot();
    clusterplot.setForegroundAlpha(0.85F);
    clusterchartpanel = new ChartPanel(clusterchart);
    ChartArea.add("Optimization", clusterchartpanel);

    //text area
    SeqText.setLineWrap(true);
    SeqText.setWrapStyleWord(true);
    SeqText.setEditable(false);
    jScrollPane.setBorder(BorderFactory
            .createCompoundBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Debug"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)), jScrollPane.getBorder()));
    textPanel.add(jScrollPane);
    //this next line is a hack to fix the ScrollPane size when the chart is scrolled
    jScrollPane.setPreferredSize(jScrollPane.getPreferredSize());
    //auto scroll to added text
    SeqText.setAutoscrolls(true);
    jScrollPane.setAutoscrolls(true);

    //center panel layout
    GroupLayout centerlayout = new GroupLayout(fCenter);
    fCenter.setLayout(centerlayout);
    ////Create a sequential and a parallel groups
    SequentialGroup h1 = centerlayout.createSequentialGroup();
    SequentialGroup v1 = centerlayout.createSequentialGroup();
    ////grouping
    h1.addGroup(centerlayout.createParallelGroup().addComponent(ChartArea).addComponent(textPanel));
    centerlayout.setHorizontalGroup(h1);
    ////more grouping
    v1.addGroup(centerlayout.createParallelGroup().addComponent(ChartArea));
    v1.addGroup(centerlayout.createParallelGroup().addComponent(textPanel));
    centerlayout.setVerticalGroup(v1);

    //CG Panel (search settings panel)
    CGPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Search Settings"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)),
            CGPanel.getBorder()));
    //set subpanel1 layout
    GroupLayout CGsublayout1 = new GroupLayout(CGsubPanel1);
    CGsubPanel1.setLayout(CGsublayout1);
    ////Create a sequential and a parallel groups
    SequentialGroup h4 = CGsublayout1.createSequentialGroup();
    SequentialGroup v4 = CGsublayout1.createSequentialGroup();
    ////grouping
    h4.addGroup(CGsublayout1.createParallelGroup().addComponent(searchPatternLabel).addComponent(minCGsLabel)
            .addComponent(maxCGsLabel).addComponent(CGstepLabel).addComponent(smoothCheckBox)
            .addComponent(CGApplyButton).addComponent(CGsetCurrLabel));
    h4.addGroup(CGsublayout1.createParallelGroup().addComponent(searchPatternText).addComponent(minCGsText)
            .addComponent(maxCGsText).addComponent(CGstepText).addComponent(smoothText)
            .addComponent(CGResetButton).addComponent(CGcurrText));
    CGsublayout1.setHorizontalGroup(h4);
    ////more grouping
    v4.addGroup(CGsublayout1.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(searchPatternLabel).addComponent(searchPatternText));
    v4.addContainerGap(5, 5);
    v4.addGroup(CGsublayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(minCGsLabel)
            .addComponent(minCGsText));
    v4.addContainerGap(5, 5);
    v4.addGroup(CGsublayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(maxCGsLabel)
            .addComponent(maxCGsText));
    v4.addContainerGap(5, 5);
    v4.addGroup(CGsublayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(CGstepLabel)
            .addComponent(CGstepText));
    v4.addContainerGap(5, 5);
    v4.addGroup(CGsublayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(smoothCheckBox)
            .addComponent(smoothText));
    v4.addContainerGap(5, 5);
    v4.addGroup(CGsublayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(CGApplyButton)
            .addComponent(CGResetButton));
    v4.addContainerGap(15, 15);
    v4.addGroup(CGsublayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(CGsetCurrLabel)
            .addComponent(CGcurrText));
    CGsublayout1.setVerticalGroup(v4);

    //set subpanel2 layout
    GroupLayout CGsublayout2 = new GroupLayout(CGsubPanel2);
    CGsubPanel2.setLayout(CGsublayout2);
    ////Create a sequential and a parallel groups
    SequentialGroup hSettingsSub2 = CGsublayout2.createSequentialGroup();
    SequentialGroup vSettingsSub2 = CGsublayout2.createSequentialGroup();

    ////horizontal grouping
    hSettingsSub2.addGroup(CGsublayout2.createParallelGroup().addComponent(CGsetCurrLabel));
    hSettingsSub2.addContainerGap(25, 25);
    hSettingsSub2.addGroup(CGsublayout2.createParallelGroup().addComponent(CGcurrText));
    hSettingsSub2.addContainerGap(25, 25);
    hSettingsSub2.addGroup(CGsublayout2.createParallelGroup().addComponent(CGsetCurrButton));
    CGsublayout2.setHorizontalGroup(hSettingsSub2);
    ////vertical grouping
    vSettingsSub2.addGroup(CGsublayout2.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(CGsetCurrLabel).addComponent(CGcurrText).addComponent(CGsetCurrButton));
    CGsublayout2.setVerticalGroup(vSettingsSub2);

    //set overall layout (subpanel3)
    GroupLayout CGsublayout3 = new GroupLayout(CGsubPanel3);
    CGsubPanel3.setLayout(CGsublayout3);
    ////Create a sequential and a parallel groups
    SequentialGroup h5 = CGsublayout3.createSequentialGroup();
    SequentialGroup v5 = CGsublayout3.createSequentialGroup();
    ////grouping
    h5.addGroup(CGsublayout3.createParallelGroup().addComponent(caseCheckBox).addComponent(CGsubPanel1)
            .addComponent(CGsubPanel2));
    CGsublayout3.setHorizontalGroup(h5);
    ////more grouping
    v5.addGroup(CGsublayout3.createParallelGroup().addComponent(caseCheckBox));
    v5.addContainerGap(5, 5);
    v5.addGroup(CGsublayout3.createParallelGroup().addComponent(CGsubPanel1));
    v5.addContainerGap(5, 5);
    v5.addGroup(CGsublayout3.createParallelGroup().addComponent(CGsubPanel2));
    CGsublayout3.setVerticalGroup(v5);
    //add to resizable container
    CGPanel.add(CGsubPanel3);
    //button and slider listeners
    CGApplyButton.addActionListener(new ListenCGApplyButton());
    CGResetButton.addActionListener(new ListenCGResetButton());
    CGsetCurrButton.addActionListener(new ListenCGsetCurrButton());
    CGcurrText.addActionListener(new ListenCGsetCurrButton());

    //minimum area
    findminPanel.setVisible(true);
    findminPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Find Minimum"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)),
            findminPanel.getBorder()));
    GroupLayout minlayout = new GroupLayout(findminPanel);
    findminPanel.setLayout(minlayout);

    ////Create a sequential and a parallel groups
    SequentialGroup h2 = minlayout.createSequentialGroup();
    SequentialGroup v2 = minlayout.createSequentialGroup();

    ////group find minimum and find all buttons
    SequentialGroup hFindMinButtons = minlayout.createSequentialGroup();
    SequentialGroup vFindMinButtons = minlayout.createSequentialGroup();
    hFindMinButtons.addGroup(minlayout.createParallelGroup().addComponent(CalcButton));
    hFindMinButtons.addGroup(minlayout.createParallelGroup().addComponent(CalcAllButton));
    vFindMinButtons.addGroup(minlayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
            .addComponent(CalcButton).addComponent(CalcAllButton));
    ////general grouping
    h2.addGroup(minlayout.createParallelGroup().addComponent(minLabel).addComponent(maxLabel)
            .addComponent(ClearButton));
    h2.addContainerGap(5, 5);
    h2.addGroup(minlayout.createParallelGroup().addComponent(minText).addComponent(maxText)
            .addGroup(hFindMinButtons));
    h2.addContainerGap(5, 5);
    h2.addGroup(minlayout.createParallelGroup().addComponent(minGrabButton).addComponent(maxGrabButton)
            .addComponent(CancelButton));
    minlayout.setHorizontalGroup(h2);
    ////more grouping
    v2.addGroup(minlayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(minLabel)
            .addComponent(minText).addComponent(minGrabButton));
    v2.addContainerGap(5, 5);
    v2.addGroup(minlayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(maxLabel)
            .addComponent(maxText).addComponent(maxGrabButton));
    v2.addContainerGap(5, 5);
    v2.addContainerGap(5, 5);
    v2.addGroup(minlayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(ClearButton)
            .addGroup(vFindMinButtons).addComponent(CancelButton));
    minlayout.setVerticalGroup(v2);
    //add button listeners
    ClearButton.addActionListener(new ListenClearButton());
    CalcButton.addActionListener(new ListenCalcButton());
    CalcAllButton.addActionListener(new ListenCalcAllButton());
    CancelButton.addActionListener(new ListenCancelButton());
    minGrabButton.addActionListener(new ListenminGrabButton());
    maxGrabButton.addActionListener(new ListenmaxGrabButton());

    //axes panel
    mnuItemSetAxes.setState(false);
    setaxesPanel.setVisible(false);
    setaxesPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Set Domain"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)),
            setaxesPanel.getBorder()));
    GroupLayout setaxeslayout = new GroupLayout(setaxesPanel);
    setaxesPanel.setLayout(setaxeslayout);
    ////Create a sequential and a parallel groups
    SequentialGroup h6 = setaxeslayout.createSequentialGroup();
    SequentialGroup v6 = setaxeslayout.createSequentialGroup();
    ////grouping
    h6.addGroup(setaxeslayout.createParallelGroup().addComponent(mindomainLabel).addComponent(maxdomainLabel)
            .addComponent(SetDomainButton));
    h6.addContainerGap(5, 5);
    h6.addGroup(setaxeslayout.createParallelGroup().addComponent(mindomainText).addComponent(maxdomainText)
            .addComponent(ResetDomainButton));
    setaxeslayout.setHorizontalGroup(h6);
    ////more grouping
    v6.addGroup(setaxeslayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(mindomainLabel)
            .addComponent(mindomainText));
    v6.addContainerGap(5, 5);
    v6.addGroup(setaxeslayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(maxdomainLabel)
            .addComponent(maxdomainText));
    v6.addContainerGap(5, 5);
    v6.addGroup(setaxeslayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(SetDomainButton)
            .addComponent(ResetDomainButton));
    setaxeslayout.setVerticalGroup(v6);
    //add button listeners
    SetDomainButton.addActionListener(new ListenSetDomainButton());
    ResetDomainButton.addActionListener(new ListenResetDomainButton());

    //east panel layout
    GroupLayout eastlayout = new GroupLayout(fEast);
    fEast.setLayout(eastlayout);
    ////Create a sequential and a parallel groups
    SequentialGroup h3 = eastlayout.createSequentialGroup();
    SequentialGroup v3 = eastlayout.createSequentialGroup();
    ////grouping
    h3.addGroup(eastlayout.createParallelGroup().addComponent(CGPanel).addComponent(findminPanel)
            .addComponent(setaxesPanel));
    eastlayout.setHorizontalGroup(h3);
    ////more grouping
    v3.addGroup(eastlayout.createParallelGroup().addComponent(CGPanel));
    v3.addGroup(eastlayout.createParallelGroup().addComponent(findminPanel));
    v3.addGroup(eastlayout.createParallelGroup().addComponent(setaxesPanel));
    eastlayout.setVerticalGroup(v3);

    //listen for exit signals
    f.addWindowListener(new ListenCloseWdw());
    mnuItemQuit.addActionListener(new ListenMenuQuit());

    //listen for exit signals
    f.addWindowListener(new ListenCloseWdw());
    mnuItemClearData.addActionListener(new ListenClearData());

    //listen for open signal
    mnuItemOpenFasta.addActionListener(new ListenMenuOpenFasta());

    //listen for open signal
    mnuItemOpenBed.addActionListener(new ListenMenuOpenBed());

    //listen for save position signal
    mnuItemSavePositions.addActionListener(new ListenMenuSavePositions());

    //listen for save cluster signal
    mnuItemSaveClusters.addActionListener(new ListenMenuSaveClusters());

    //listen for save histogram chart signal
    mnuItemSaveChrt.addActionListener(new ListenMenuSaveChrt());

    //listen for save chart signal
    mnuItemSaveMinChrt.addActionListener(new ListenMenuSaveMinChrt());

    //listen for save cluster chart signal
    mnuItemSaveClusterChrt.addActionListener(new ListenMenuSaveClusterChrt());

    //listen for save histogram chart in grayscale signal;
    mnuItemSaveGrayChrt.addActionListener(new ListenMenuSaveGrayChrt());

    //listen for save chart signal
    mnuItemSaveGrayMinChrt.addActionListener(new ListenMenuSaveGrayMinChrt());

    //listen for save cluster chart signal
    mnuItemSaveGrayClusterChrt.addActionListener(new ListenMenuSaveGrayClusterChrt());

    //listen for edit histogram properties signal
    mnuItemChartProps.addActionListener(new ListenMenuChartProps());

    //listen for edit minima chart properties signal
    mnuItemMinimaProps.addActionListener(new ListenMenuMinimaProps());

    //listen for edit optimization chart properties signal
    mnuItemClusterProps.addActionListener(new ListenMenuClusterProps());

    //listen for find minimum signal
    mnuItemFindMin.addActionListener(new ListenMenuFindMin());

    //listen for find minimum signal
    mnuItemSetAxes.addActionListener(new ListenMenuSetAxes());

    //listen for show gridlines
    mnuItemShowGrid.addActionListener(new ListenMenuShowGrid());

    //other menu items

    //garbage collect
    //System.gc();
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

private TextTitle createTitle(UITitle titlecomp) {
    FacesContext context = FacesContext.getCurrentInstance();
    String text = FacesUtils.getFormattedValue(context, titlecomp, titlecomp.getValue());
    TextTitle title = new TextTitle(text);

    Font font = titlecomp.getFont();
    if (font != null) {
        title.setFont(font);//from  w  w  w .  j a  v a  2  s . c  o  m
    }

    Paint color = titlecomp.getColor();
    if (color != null) {
        title.setPaint(color);
    }

    Paint bgcolor = titlecomp.getBackgroundColor();
    if (bgcolor != null) {
        title.setBackgroundPaint(bgcolor);
    }

    PositionType position = titlecomp.getPosition();
    if (position != null) {
        setTitlePosition(title, position);
    }

    return title;
}

From source file:mt.LengthDistribution.java

public static void GetLengthDistributionArrayatTime(ArrayList<File> AllMovies, double[] calibration,
        final int framenumber) {

    ArrayList<Double> maxlist = new ArrayList<Double>();
    for (int i = 0; i < AllMovies.size(); ++i) {

        ArrayList<Pair<Integer, Double>> lengthlist = LengthDistribution.LengthdistroatTime(AllMovies.get(i),
                framenumber);//from   w  ww .  j a v  a 2 s . c  o m

        for (int index = 0; index < lengthlist.size(); ++index) {
            if (lengthlist.get(index).getB() != Double.NaN && lengthlist.get(index).getB() > 0)
                maxlist.add(lengthlist.get(index).getB());

        }
    }
    Collections.sort(maxlist);

    int min = 0;
    int max = 0;
    if (maxlist.size() > 0)
        max = (int) Math.round(maxlist.get(maxlist.size() - 1)) + 1;
    XYSeries counterseries = new XYSeries("MT length distribution");
    XYSeries Logcounterseries = new XYSeries("MT Log length distribution");
    final ArrayList<Point> points = new ArrayList<Point>();
    for (int length = 0; length < max; ++length) {

        HashMap<Integer, Integer> frameseed = new HashMap<Integer, Integer>();

        int count = 0;
        for (int i = 0; i < AllMovies.size(); ++i) {

            File file = AllMovies.get(i);

            ArrayList<FLSobject> currentobject = Tracking.loadMTStat(file);

            if (currentobject != null)
                for (int index = 0; index < currentobject.size(); ++index) {
                    ArrayList<Integer> seedlist = new ArrayList<Integer>();
                    if (currentobject.get(index).length >= length
                            && currentobject.get(index).Framenumber == framenumber) {
                        seedlist.add(currentobject.get(index).seedID);
                        if (frameseed.get(currentobject.get(index).Framenumber) != null
                                && frameseed.get(currentobject.get(index).Framenumber) != Double.NaN) {

                            int currentcount = frameseed.get(currentobject.get(index).Framenumber);
                            frameseed.put(currentobject.get(index).Framenumber, seedlist.size() + currentcount);
                        } else if (currentobject.get(index) != null)
                            frameseed.put(currentobject.get(index).Framenumber, seedlist.size());

                    }

                }

        }

        // Get maxima length, count
        int maxvalue = Integer.MIN_VALUE;

        for (int key : frameseed.keySet()) {

            int Count = frameseed.get(key);

            if (Count >= maxvalue)
                maxvalue = Count;
        }

        if (maxvalue != Integer.MIN_VALUE) {
            counterseries.add(length, maxvalue);

            if (maxvalue > 0) {

                System.out.println("Max " + maxvalue);
                Logcounterseries.add((length), Math.log(maxvalue));
                points.add(new Point(new double[] { length, Math.log(maxvalue) }));
            }

        }
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    final XYSeriesCollection nofitdataset = new XYSeriesCollection();
    dataset.addSeries(counterseries);
    nofitdataset.addSeries(counterseries);
    final XYSeriesCollection Logdataset = new XYSeriesCollection();
    Logdataset.addSeries(Logcounterseries);

    final JFreeChart chart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT",
            "Length (micrometer)", dataset);
    final JFreeChart nofitchart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT",
            "Length (micrometer)", nofitdataset);
    // Fitting line to log of the length distribution
    interpolation.Polynomial poly = new interpolation.Polynomial(1);
    try {

        poly.fitFunction(points);

    } catch (NotEnoughDataPointsException e) {

    }
    DisplayPoints.display(nofitchart, new Dimension(800, 500));
    dataset.addSeries(Tracking.drawexpFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5,
            "Exponential fit"));
    NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
    nf.setMaximumFractionDigits(3);
    TextTitle legendText = new TextTitle("Mean Length" + " : " + nf.format(-1.0 / poly.getCoefficients(1))
            + "  " + "Standard Deviation" + " : " + nf.format(poly.SSE));
    legendText.setPosition(RectangleEdge.RIGHT);

    DisplayPoints.display(chart, new Dimension(800, 500));
    chart.addSubtitle(legendText);

    System.out.println("Series count" + dataset.getSeriesCount());
    final JFreeChart logchart = ChartFactory.createScatterPlot("MT Log length distribution",
            "Length (micrometer)", "Number of MT", Logdataset);
    //     DisplayPoints.display(logchart, new Dimension(800, 500));
    for (int i = 1; i >= 0; --i)
        System.out.println(poly.getCoefficients(i) + "  " + "x" + " X to the power of " + i);

    //  Logdataset.addSeries(Tracking.drawFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Straight line fit"));
    WriteLengthdistroFile(AllMovies, counterseries, framenumber);
}

From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java

private JFreeChart createPieChart(final Account a) {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    Objects.requireNonNull(a);/*from w  w w  . ja v a  2  s .c  o  m*/

    PieDataset data = createPieDataSet(a);
    PiePlot plot = new PiePlot(data);

    // rebuilt each time because they're based on the account's commodity
    CurrencyNode defaultCurrency = engine.getDefaultCurrency();
    NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
    NumberFormat percentFormat = new DecimalFormat("0.0#%");
    defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
    percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);

    plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);

    plot.setLabelGap(.02);
    plot.setInteriorGap(.1);

    // if we had to add a section for the account (because it has it's
    // own transactions, not just child accounts), separate it from children.
    if (data.getIndex(a) != -1) {
        plot.setExplodePercent(a, .10);
    }

    String title;

    // pick an appropriate title
    if (a.getAccountType() == AccountType.EXPENSE) {
        title = rb.getString("Title.PercentExpense");
    } else if (a.getAccountType() == AccountType.INCOME) {
        title = rb.getString("Title.PercentIncome");
    } else {
        title = rb.getString("Title.PercentDist");
    }

    title = title + " - " + a.getPathName();

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    BigDecimal total = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();

    String subtitle = valueFormat.format(total);
    if (!defaultCurrency.equals(a.getCurrencyNode())) {
        BigDecimal totalDefaultCurrency = total.multiply(a.getCurrencyNode().getExchangeRate(defaultCurrency));
        NumberFormat defaultValueFormat = CommodityFormat.getFullNumberFormat(defaultCurrency);
        subtitle += "  -  " + defaultValueFormat.format(totalDefaultCurrency);
    }
    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:jgnash.ui.report.compiled.PayeePieChart.java

private JFreeChart createPieChart(Account a, PieDataset[] data, int index) {
    PiePlot plot = new PiePlot(data[index]);

    // rebuilt each time because they're based on the account's commodity
    NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
    NumberFormat percentFormat = new DecimalFormat("0.0#%");
    defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
    percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);

    plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);

    plot.setLabelGap(.02);/*from  ww w. jav  a2  s . c o m*/
    plot.setInteriorGap(.1);

    BigDecimal thisTotal = BigDecimal.ZERO;
    for (int i = 0; i < data[index].getItemCount(); i++) {
        thisTotal = thisTotal.add((BigDecimal) (data[index].getValue(i)));
    }
    BigDecimal acTotal = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();

    String title = "";
    String subtitle = "";

    // pick an appropriate title(s)
    if (index == 0) {
        title = a.getPathName();
        subtitle = rb.getString("Column.Credit") + " : " + valueFormat.format(thisTotal);
    } else if (index == 1) {
        title = rb.getString("Column.Balance") + " : " + valueFormat.format(acTotal);
        subtitle = rb.getString("Column.Debit") + " : " + valueFormat.format(thisTotal);
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:asl.util.PlotMaker.java

public void plotPSD(double per[], double[] model, double[] nhnmPer, double[] nhnm, double[] psd,
        String modelName, String plotString) {

    // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString
    final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR),
            date.get(Calendar.DAY_OF_YEAR), station, channel, plotString);
    // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png"
    final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR),
            date.get(Calendar.DAY_OF_YEAR), station, channel, plotString);
    File outputFile = new File(pngName);

    // Check that we will be able to output the file without problems and if not --> return
    if (!checkFileOut(outputFile)) {
        System.out.format(//w  ww .  j  ava 2  s. c o m
                "== plotPSD: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n",
                pngName);
        return;
    }

    Boolean plotNHNM = false;
    //if (nhnm.length > 0) {
    if (nhnm != null) {
        plotNHNM = true;
    }

    final XYSeries series1 = new XYSeries(modelName);
    final XYSeries series2 = new XYSeries(channel.toString());
    final XYSeries series3 = new XYSeries("NHNM");

    for (int k = 0; k < per.length; k++) {
        series1.add(per[k], model[k]);
        series2.add(per[k], psd[k]);
    }

    if (plotNHNM) {
        for (int k = 0; k < nhnmPer.length; k++) {
            series3.add(nhnmPer[k], nhnm[k]);
        }
    }

    //final XYItemRenderer renderer = new StandardXYItemRenderer();
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    Rectangle rectangle = new Rectangle(3, 3);

    renderer.setSeriesShape(0, rectangle);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(0, true);

    renderer.setSeriesShape(1, rectangle);
    renderer.setSeriesShapesVisible(1, true);
    renderer.setSeriesLinesVisible(1, false);

    renderer.setSeriesShape(2, rectangle);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesLinesVisible(2, true);

    Paint[] paints = new Paint[] { Color.blue, Color.red, Color.black };
    renderer.setSeriesPaint(0, paints[0]);
    renderer.setSeriesPaint(1, paints[1]);
    renderer.setSeriesPaint(2, paints[2]);

    final NumberAxis rangeAxis1 = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB");
    //rangeAxis1.setRange( new Range(-190, -120));
    rangeAxis1.setRange(new Range(-190, -95));
    rangeAxis1.setTickUnit(new NumberTickUnit(5.0));

    final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Period (sec)");
    horizontalAxis.setRange(new Range(0.05, 10000));

    final XYSeriesCollection seriesCollection = new XYSeriesCollection();
    seriesCollection.addSeries(series1);
    seriesCollection.addSeries(series2);

    if (plotNHNM) {
        seriesCollection.addSeries(series3);
    }

    final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, rangeAxis1, renderer);

    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.black);
    xyplot.setDomainGridlinePaint(Color.black);

    final JFreeChart chart = new JFreeChart(xyplot);
    chart.setTitle(new TextTitle(plotTitle));

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");

    }
}

From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.ChartPostProcessorImpl.java

/**
 * This method renders a subtitle above the graph, in case the subtitle string is not null or "". Set the subTitle in the jsp via the param tag,
 * using the keyword "subtitle": <cewolf:chartpostprocessor id="chartPostProcessorImpl" > <cewolf:param name="subtitle"
 * value="${dataTable.subTitle}"/> </cewolf:chartpostprocessor>
 * @param chart/*from www.  j  ava2 s  .com*/
 * @param params
 */
@SuppressWarnings("rawtypes")
private void setSubTitle(final Object chart, final Map params) {
    final String subtitleString = (String) params.get("subtitle");
    if (subtitleString != null && subtitleString.trim().length() > 0) {
        final TextTitle subtitle = new TextTitle(subtitleString);
        subtitle.setFont(subtitle.getFont().deriveFont(11f)); // TODO font size may be parameterized later on???
        ((JFreeChart) chart).addSubtitle(subtitle);
    }
}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Creates and returns a new <code>JFreeChart</code> instance that
 * reflects the specified parameters (which should be equivalent to
 * a parameter map returned by HttpServletRequest.getParameterMap() for
 * a valid URI for the Google Chart API.
 *
 * @param params  the parameters (<code>null</code> not permitted).
 * @param font    the font to use to draw titles, labels and legends.
 *
 * @return A chart corresponding to the specification in the supplied
 *         parameters.//from w  ww . ja  v  a 2 s .  c o  m
 */
public static JFreeChart buildChart(Map params, Font font) {
    if (params == null) {
        throw new IllegalArgumentException("Null 'params' argument.");
    }

    JFreeChart chart = null;

    // *** CHART TYPE **
    String[] chartType = (String[]) params.get("cht");
    int dataType = -1; // 0 = PieDataset; 1 = XYDataset; 2 = special

    // pie charts: 'p' and 'p3'
    if (chartType[0].equals("p")) {
        chart = createPieChart();
        dataType = 0;
    } else if (chartType[0].equals("p3")) {
        chart = createPieChart3D();
        dataType = 0;
    }
    // line chart: 'lc'
    else if (chartType[0].equals("lc")) {
        chart = createLineChart();
        dataType = 1;
    }
    // sparkline: 'ls'
    else if (chartType[0].equals("ls")) {
        chart = createSparklineChart();
        dataType = 1;
    }
    // xy chart: 'lxy'
    else if (chartType[0].equals("lxy")) {
        chart = createLineChart();
        dataType = 3;
    }
    // bar charts: 'bhs', 'bhg', 'bhs' and 'bhg'
    else if (chartType[0].equals("bhs")) {
        chart = createStackedBarChart(PlotOrientation.HORIZONTAL);
        dataType = 2;
    } else if (chartType[0].equals("bhg")) {
        chart = createBarChart(PlotOrientation.HORIZONTAL);
        dataType = 2;
    } else if (chartType[0].equals("bvs")) {
        chart = createStackedBarChart(PlotOrientation.VERTICAL);
        dataType = 2;
    } else if (chartType[0].equals("bvg")) {
        chart = createBarChart(PlotOrientation.VERTICAL);
        dataType = 2;
    } else if (chartType[0].equals("bhs3")) {
        chart = createStackedBarChart3D(PlotOrientation.HORIZONTAL);
        dataType = 2;
    } else if (chartType[0].equals("bhg3")) {
        chart = createBarChart3D(PlotOrientation.HORIZONTAL);
        dataType = 2;
    } else if (chartType[0].equals("bvs3")) {
        chart = createStackedBarChart3D(PlotOrientation.VERTICAL);
        dataType = 2;
    } else if (chartType[0].equals("bvg3")) {
        chart = createBarChart3D(PlotOrientation.VERTICAL);
        dataType = 2;
    }
    // scatter chart: 's'
    else if (chartType[0].equals("s")) {
        chart = createScatterChart();
        dataType = 4;
    } else if (chartType[0].equals("v")) {
        throw new RuntimeException("Venn diagrams not implemented.");
        // TODO: fix this.
    } else {
        throw new RuntimeException("Unknown chart type: " + chartType[0]);
    }

    chart.getPlot().setOutlineVisible(false);

    // *** CHART AXES ***
    List axes = new java.util.ArrayList();
    String[] axisStr = (String[]) params.get("chxt");
    if (axisStr != null) {
        if (chart.getPlot() instanceof XYPlot) {
            XYPlot plot = (XYPlot) chart.getPlot();
            processAxisStr(plot, axisStr[0], axes);
        } else if (chart.getPlot() instanceof CategoryPlot) {
            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                processAxisStrV(plot, axisStr[0], axes);
            } else {
                processAxisStrH(plot, axisStr[0], axes);
            }
        }
    }

    // *** AXIS RANGES ***
    String[] axisRangeStr = (String[]) params.get("chxr");
    if (axisRangeStr != null) {
        String[] ranges = breakString(axisRangeStr[0], '|');
        for (int i = 0; i < ranges.length; i++) {
            int comma1 = ranges[i].indexOf(',');
            int comma2 = ranges[i].indexOf(',', comma1 + 1);
            int axisIndex = Integer.parseInt(ranges[i].substring(0, comma1));
            float lowerBound = Float.parseFloat(ranges[i].substring(comma1 + 1, comma2));
            float upperBound = Float.parseFloat(ranges[i].substring(comma2 + 1));
            Axis axis = (Axis) axes.get(axisIndex);
            if (axis instanceof GValueAxis) {
                GValueAxis gaxis = (GValueAxis) axis;
                gaxis.setLabelAxisStart(lowerBound);
                gaxis.setLabelAxisEnd(upperBound);
            }
        }
    }

    // *** AXIS LABELS ***
    String[] axisLabelStr = (String[]) params.get("chxl");
    if (axisLabelStr != null) {
        Pattern p = Pattern.compile("\\d+:\\|");
        Matcher m = p.matcher(axisLabelStr[0]);
        if (m.find()) {
            int keyStart = m.start();
            int labelStart = m.end();
            while (m.find(labelStart)) {
                String keyStr = axisLabelStr[0].substring(keyStart, labelStart - 2);
                int axisIndex = Integer.parseInt(keyStr);
                keyStart = m.start();
                String labelStr = axisLabelStr[0].substring(labelStart, keyStart - 1);
                String[] labels = breakString(labelStr, '|');
                GLabelledAxis axis = (GLabelledAxis) axes.get(axisIndex);
                axis.setTickLabels(Arrays.asList(labels));
                labelStart = m.end();
            }
            // process the final item
            String keyStr = axisLabelStr[0].substring(keyStart, labelStart - 2);
            String labelStr = axisLabelStr[0].substring(labelStart);
            int axisIndex = Integer.parseInt(keyStr);
            if (labelStr.endsWith("|")) {
                labelStr = labelStr.substring(0, labelStr.length() - 1);
            }
            String[] labels = breakString(labelStr, '|');
            GLabelledAxis axis = (GLabelledAxis) axes.get(axisIndex);
            axis.setTickLabels(Arrays.asList(labels));

        } else {
            throw new RuntimeException("No matching pattern!");
        }

    }

    // ** EXPLICIT AXIS LABEL POSITIONS
    String[] axisPositionStr = (String[]) params.get("chxp");
    if (axisPositionStr != null) {
        String[] positions = breakString(axisPositionStr[0], '|');
        for (int i = 0; i < positions.length; i++) {
            int c1 = positions[i].indexOf(',');
            int axisIndex = Integer.parseInt(positions[i].substring(0, c1));
            String remainingStr = positions[i].substring(c1 + 1);
            String[] valueStr = breakString(remainingStr, ',');
            List tickValues = new java.util.ArrayList(valueStr.length);
            Axis axis = (Axis) axes.get(axisIndex);
            if (axis instanceof GValueAxis) {
                GValueAxis gaxis = (GValueAxis) axes.get(axisIndex);
                for (int j = 0; j < valueStr.length; j++) {
                    float pos = Float.parseFloat(valueStr[j]);
                    tickValues.add(new Float(pos));
                }
                gaxis.setTickLabelPositions(tickValues);
            }
            // FIXME: what about a CategoryAxis?
        }
    }

    // *** CHART TITLE ***
    String[] titleStr = (String[]) params.get("chtt");
    if (titleStr != null) {
        // process the title
        String[] s = breakString(titleStr[0], '|');
        for (int i = 0; i < s.length; i++) {
            TextTitle t = new TextTitle(s[i].replace('+', ' '));
            t.setPaint(Color.darkGray);
            // Google seems to use 14pt fonts for titles and 12pt fonts for
            // all other text. Make sure this relationship remains.
            t.setFont(font.deriveFont(font.getSize2D() * 14f / 12f));
            chart.addSubtitle(t);
        }
        // and the font and colour
        String[] fontStr = (String[]) params.get("chts");
        if (fontStr != null) {
            int c1 = fontStr[0].indexOf(',');
            String colorStr = null;
            String fontSizeStr = null;
            if (c1 != -1) {
                colorStr = fontStr[0].substring(0, c1);
                fontSizeStr = fontStr[0].substring(c1 + 1);
            } else {
                colorStr = fontStr[0];
            }
            Color color = parseColor(colorStr);
            int size = 12;
            if (fontSizeStr != null) {
                size = Integer.parseInt(fontSizeStr);
            }
            for (int i = 0; i < chart.getSubtitleCount(); i++) {
                Title t = chart.getSubtitle(i);
                if (t instanceof TextTitle) {
                    TextTitle tt = (TextTitle) t;
                    tt.setPaint(color);
                    tt.setFont(font.deriveFont((float) size));
                }
            }
        }
    }

    // *** CHART DATA ***
    String[] dataStr = (String[]) params.get("chd");
    String scalingStr = null;
    if (dataStr.length > 0 && dataStr[0].startsWith("t:")) {
        // Only look at chds when text encoding is used
        String[] chds = (String[]) params.get("chds");
        if (chds != null && chds.length > 0) {
            scalingStr = chds[0];
        }
    }

    // we'll also process an optional second dataset that is provided as
    // an Eastwood extension...this isn't part of the Google Chart API
    String[] d2Str = (String[]) params.get("ewd2");

    // 'p' and 'p3' - create PieDataset
    if (dataType == 0) {
        PieDataset dataset = DataUtilities.parsePieDataset(dataStr[0], scalingStr);
        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setDataset(dataset);

        // ignore d2Str as there is currently no need for a second pie
        // dataset.
    }

    // 'lc' - create XYDataset
    else if (dataType == 1) {
        XYPlot plot = (XYPlot) chart.getPlot();
        XYDataset dataset = DataUtilities.parseXYDataset(dataStr[0], scalingStr);
        plot.setDataset(dataset);

        if (d2Str != null) { // an Eastwood extension
            XYDataset d2 = DataUtilities.parseXYDataset(d2Str[0], scalingStr);
            plot.setDataset(1, d2);
        }
    }

    // 'bhs', 'bhg', 'bvs', 'bvg'
    else if (dataType == 2) {
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryDataset dataset = DataUtilities.parseCategoryDataset(dataStr[0], scalingStr);
        plot.setDataset(dataset);

        if (d2Str != null) { // an Eastwood extension
            CategoryDataset d2 = DataUtilities.parseCategoryDataset(d2Str[0], scalingStr);
            plot.setDataset(1, d2);
        }
    }

    // 'lxy'
    else if (dataType == 3) {
        XYPlot plot = (XYPlot) chart.getPlot();
        XYDataset dataset = DataUtilities.parseXYDataset2(dataStr[0], scalingStr);
        plot.setDataset(dataset);

        if (d2Str != null) { // an Eastwood extension
            XYDataset d2 = DataUtilities.parseXYDataset2(d2Str[0], scalingStr);
            plot.setDataset(1, d2);
        }
    } else if (dataType == 4) {
        XYPlot plot = (XYPlot) chart.getPlot();
        XYSeriesCollection dataset = DataUtilities.parseScatterDataset(dataStr[0], scalingStr);
        if (dataset.getSeriesCount() > 1) {
            dataset.removeSeries(1);
        }
        plot.setDataset(dataset);
        if (d2Str != null) { // an Eastwood extension
            XYDataset d2 = DataUtilities.parseXYDataset2(d2Str[0], scalingStr);
            plot.setDataset(1, d2);
        }
    }

    if (chart.getPlot() instanceof XYPlot) {
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.getDomainAxis().setLabelFont(font);
        plot.getDomainAxis().setTickLabelFont(font);
        plot.getRangeAxis().setLabelFont(font);
        plot.getRangeAxis().setTickLabelFont(font);
    } else if (chart.getPlot() instanceof CategoryPlot) {
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.getDomainAxis().setLabelFont(font);
        plot.getDomainAxis().setTickLabelFont(font);
        plot.getRangeAxis().setLabelFont(font);
        plot.getRangeAxis().setTickLabelFont(font);
    }

    // *** CHART COLOURS ***
    String[] colorStr = (String[]) params.get("chco");
    if (colorStr != null) {
        Color[] colors = parseColors(colorStr[0]);
        if (dataType == 0) {
            PiePlot plot = (PiePlot) chart.getPlot();
            applyColorsToPiePlot(plot, colors);
        } else {
            AbstractRenderer renderer = null;
            if (chart.getPlot() instanceof CategoryPlot) {
                CategoryPlot plot = (CategoryPlot) chart.getPlot();
                renderer = (AbstractRenderer) plot.getRenderer();
                renderer.setBasePaint(colors[0]);
            } else if (chart.getPlot() instanceof XYPlot) {
                XYPlot plot = (XYPlot) chart.getPlot();
                renderer = (AbstractRenderer) plot.getRenderer();
                renderer.setBasePaint(colors[colors.length - 1]);
            }
            for (int i = 0; i < colors.length; i++) {
                renderer.setSeriesPaint(i, colors[i]);
            }
        }
    } else {
        Plot plot = chart.getPlot();
        if (plot instanceof PiePlot) {
            applyColorsToPiePlot((PiePlot) chart.getPlot(), new Color[] { new Color(255, 153, 0) });
        }
    }

    // *** CHART LINE STYLES ***
    String[] lineStr = (String[]) params.get("chls");
    if (lineStr != null && chart.getPlot() instanceof XYPlot) {
        Stroke[] strokes = parseLineStyles(lineStr[0]);
        XYPlot plot = (XYPlot) chart.getPlot();
        XYItemRenderer renderer = plot.getRenderer();
        for (int i = 0; i < strokes.length; i++) {
            renderer.setSeriesStroke(i, strokes[i]);
        }
        renderer.setBaseStroke(strokes[strokes.length - 1]);
    }

    // *** CHART GRID LINES
    if (dataType != 0) {
        String[] gridStr = (String[]) params.get("chg");
        if (gridStr != null) {
            processGridLinesSpec(gridStr[0], chart);
        }
    }

    // *** CHART LABELS
    if (dataType == 0) { // pie chart
        String[] labelStr = (String[]) params.get("chl");
        if (labelStr != null) {
            String[] s = breakString(labelStr[0], '|');
            List labels = Arrays.asList(s);
            PiePlot plot = (PiePlot) chart.getPlot();
            if (labels.size() > 0) {
                plot.setLabelGenerator(new GPieSectionLabelGenerator(labels));
                plot.setLabelFont(font);
                plot.setLabelPaint(Color.darkGray);
            }
        }
    }

    String[] legendStr = (String[]) params.get("chdl");
    if (legendStr != null) {
        // process the title
        String[] s = breakString(legendStr[0], '|');
        List labels = Arrays.asList(s);
        if (labels.size() > 0) {
            Plot p = chart.getPlot();
            if (p instanceof CategoryPlot) {
                CategoryPlot plot = (CategoryPlot) chart.getPlot();
                BarRenderer renderer = (BarRenderer) plot.getRenderer();
                renderer.setLegendItemLabelGenerator(new GSeriesLabelGenerator(labels));
                renderer.setBaseSeriesVisibleInLegend(false);
                for (int i = 0; i < labels.size(); i++) {
                    renderer.setSeriesVisibleInLegend(i, Boolean.TRUE);
                }
            } else if (p instanceof XYPlot) {
                XYPlot plot = (XYPlot) chart.getPlot();
                XYItemRenderer renderer = plot.getRenderer();
                renderer.setLegendItemLabelGenerator(new GSeriesLabelGenerator(labels));
                renderer.setBaseSeriesVisibleInLegend(false);
                for (int i = 0; i < labels.size(); i++) {
                    renderer.setSeriesVisibleInLegend(i, Boolean.TRUE);
                }
            } else if (p instanceof PiePlot) {
                PiePlot plot = (PiePlot) chart.getPlot();
                plot.setLegendLabelGenerator(new GPieSectionLabelGenerator(labels));
            }

            LegendTitle legend = new LegendTitle(chart.getPlot());
            RectangleEdge pos = RectangleEdge.RIGHT;
            String[] chdlp = (String[]) params.get("chdlp");
            if (chdlp != null) {
                if ("b".equals(chdlp[0])) {
                    pos = RectangleEdge.BOTTOM;
                } else if ("t".equals(chdlp[0])) {
                    pos = RectangleEdge.TOP;
                } else if ("l".equals(chdlp[0])) {
                    pos = RectangleEdge.LEFT;
                }
            }
            legend.setPosition(pos);
            legend.setItemFont(font);
            legend.setItemPaint(Color.darkGray);
            chart.addSubtitle(legend);
        }
    }

    // *** CHART MARKERS ***
    String[] markerStr = (String[]) params.get("chm");
    if (markerStr != null) {
        String[] markers = breakString(markerStr[0], '|');
        for (int i = 0; i < markers.length; i++) {
            addMarker(markers[i], chart);
        }
    }

    // *** CHART FILL ***/
    String[] fillStr = (String[]) params.get("chf");
    if (fillStr != null) {
        // process the 1 or 2 fill specs
        int i = fillStr[0].indexOf('|');
        if (i == -1) {
            processFillSpec(fillStr[0], chart);
        } else {
            String fs1 = fillStr[0].substring(0, i);
            String fs2 = fillStr[0].substring(i + 1);
            processFillSpec(fs1, chart);
            processFillSpec(fs2, chart);
        }
    }

    // process the 'ewtr' tag, if present
    processEWTR(params, chart);

    return chart;

}

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

private static JFreeChart createChart6(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release",
            "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle("Number of Classes By Release"));
    TextTitle texttitle = new TextTitle(
            "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);//from w w  w.j  a  v  a2s . c om
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.14999999999999999D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    lineandshaperenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}