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

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

Introduction

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

Prototype

public ValueAxis getDomainAxis() 

Source Link

Document

Returns the domain axis with index 0.

Usage

From source file:net.sf.smbt.ui.btc.views.AbstractBlockchainView.java

public void addCharts(Composite folder) {
    chart = ChartFactory.createXYStepChart(getChartTitle(), getXAxisLabel(), getYAxisLabel(), null,
            PlotOrientation.VERTICAL, true, // legend
            true, // tooltips
            false // urls
    );//w  ww  .  j a  v  a 2  s  .  c om

    // then customise it a little...

    final XYPlot plot = chart.getXYPlot();

    chart.getTitle().setPaint(Color.LIGHT_GRAY);

    chart.setBackgroundPaint(new java.awt.Color(66, 66, 66));
    plot.setBackgroundPaint(new java.awt.Color(66, 66, 66));
    plot.getRenderer().setSeriesVisibleInLegend(false);

    plot.getRangeAxis().setTickLabelPaint(Color.LIGHT_GRAY);
    plot.getRangeAxis().setLabelPaint(Color.LIGHT_GRAY);

    plot.getDomainAxis().setTickLabelPaint(Color.LIGHT_GRAY);
    plot.getDomainAxis().setLabelPaint(Color.LIGHT_GRAY);

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));

    // and present it in a frame...

    new ChartComposite(folder, SWT.NONE, chart, true);
}

From source file:com.philng.telemetrydisplay.GraphDisplay.java

/**
 * Create the chart itself with datasets
 * @param dataset//w  ww. ja  v  a 2  s. c o m
 * @return
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart result = ChartFactory.createTimeSeriesChart("Telemetry Display", "Time", "Voltage",
            dataset, true, true, false);
    final XYPlot plot = result.getXYPlot();

    // Add in a new y axis for current
    ValueAxis currentAxis = new NumberAxis();
    currentAxis.setRange(0, 100);
    currentAxis.setLabel("Current");

    plot.setRangeAxis(1, currentAxis);
    plot.setDataset(1, createDatasetCurrent());
    plot.mapDatasetToRangeAxis(1, 1);

    // Set information for the x axis (time)
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);

    // Set the information for the voltage axis
    axis = plot.getRangeAxis();
    axis.setAutoRange(false);
    axis.setRange(0.0, 12.0);

    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setShapesFilled(true);
    }

    final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.GREEN);
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    plot.setRenderer(1, renderer2);

    return result;
}

From source file:mrmc.chart.ROCCurvePlot.java

/**
 * Sole constructor. Creates a line plot display ROC curves
 * /*from   ww w .  ja v  a2s.c om*/
 * @param title Title of the chart
 * @param xaxis x-axis label
 * @param yaxis y-axis label
 * @param treeMap Mapping of readers to a set of points defining an ROC curve
 */
public ROCCurvePlot(final String title, String xaxis, String yaxis, TreeMap<String, TreeSet<XYPair>> treeMap) {
    super(title);

    createDataset(treeMap);
    final JFreeChart chart = ChartFactory.createScatterPlot(title, xaxis, yaxis, seriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    NumberAxis domain = (NumberAxis) xyplot.getDomainAxis();
    domain.setRange(0.00, 1.00);
    domain.setTickUnit(new NumberTickUnit(0.1));
    NumberAxis range = (NumberAxis) xyplot.getRangeAxis();
    range.setRange(0.00, 1.00);
    range.setTickUnit(new NumberTickUnit(0.1));
    renderer = new XYLineAndShapeRenderer();
    chart.getXYPlot().setRenderer(renderer);
    ChartPanel chartPanel = new ChartPanel(chart);

    JPanel readerSelect = new JPanel(new WrapLayout());
    readerSeriesBoxes = new ArrayList<JCheckBox>();

    for (String r : treeMap.keySet()) {
        JCheckBox aBox = new JCheckBox("" + r);
        aBox.setSelected(false);
        aBox.addItemListener(new SeriesSelectListener());
        hideSeries("" + r);
        readerSeriesBoxes.add(aBox);
        readerSelect.add(aBox);
    }

    renderer.setSeriesShapesVisible(seriesCollection.getSeriesIndex("Vertical Average"), false);
    renderer.setSeriesStroke(seriesCollection.getSeriesIndex("Vertical Average"), new java.awt.BasicStroke(3f));
    renderer.setSeriesShapesVisible(seriesCollection.getSeriesIndex("Horizontal Average"), false);
    renderer.setSeriesStroke(seriesCollection.getSeriesIndex("Horizontal Average"),
            new java.awt.BasicStroke(3f));
    renderer.setSeriesShapesVisible(seriesCollection.getSeriesIndex("Diagonal Average"), false);
    renderer.setSeriesStroke(seriesCollection.getSeriesIndex("Diagonal Average"), new java.awt.BasicStroke(3f));
    renderer.setSeriesStroke(seriesCollection.getSeriesIndex("Pooled Average"), new java.awt.BasicStroke(3f));

    vert = new JCheckBox("Vertical Average");
    vert.setSelected(true);
    vert.addItemListener(new SeriesSelectListener());
    readerSelect.add(vert);
    horiz = new JCheckBox("Horizontal Average");
    horiz.setSelected(true);
    horiz.addItemListener(new SeriesSelectListener());
    readerSelect.add(horiz);
    diag = new JCheckBox("Diagonal Average");
    diag.setSelected(true);
    diag.addItemListener(new SeriesSelectListener());
    readerSelect.add(diag);
    pooled = new JCheckBox("Pooled Average");
    pooled.setSelected(true);
    pooled.addItemListener(new SeriesSelectListener());
    readerSelect.add(pooled);

    JCheckBox allReaders = new JCheckBox("Show Readers");
    allReaders.setSelected(false);
    allReaders.addItemListener(new ReadersSelectListener());
    readerSelect.add(allReaders);
    JCheckBox allAverages = new JCheckBox("Show Averages");
    allAverages.setSelected(true);
    allAverages.addItemListener(new AverageSelectListener());
    readerSelect.add(allAverages);

    chartPanel.setPreferredSize(new java.awt.Dimension(700, 700));
    this.add(chartPanel);
    this.add(readerSelect, BorderLayout.PAGE_END);

}

From source file:org.owasp.benchmark.score.report.ScatterScores.java

private JFreeChart display(String title, int height, int width, List<Report> toolResults) {
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    for (int i = 0; i < toolResults.size(); i++) {
        Report toolReport = toolResults.get(i);
        OverallResults overallResults = toolReport.getOverallResults();
        series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100);
    }/*from  ww w. jav  a2 s . c  o  m*/
    dataset.addSeries(series);

    chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    String fontName = "Arial";
    DecimalFormat pctFormat = new DecimalFormat("0'%'");

    theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    xyplot.setOutlineVisible(true);

    rangeAxis.setRange(-5, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);

    domainAxis.setRange(-5, 105);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    //        // setup item labels
    //        XYItemRenderer renderer = xyplot.getRenderer();
    //        Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f);
    //        for ( int i = 0; i < dataset.getSeriesCount(); i++ ) {
    //            renderer.setSeriesShape(i, circle);
    //            renderer.setSeriesPaint(i, Color.blue);
    //            String label = ""+((String)dataset.getSeries(i).getKey());
    //            int idx = label.indexOf( ':');
    //            label = label.substring( 0, idx );
    //            StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label); 
    //            renderer.setSeriesItemLabelGenerator(i, generator); 
    //            renderer.setSeriesItemLabelsVisible(i, true);
    //            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER );
    //            renderer.setSeriesPositiveItemLabelPosition(i, position);
    //        }

    makeDataLabels(toolResults, xyplot);
    makeLegend(toolResults, 57, 48, dataset, xyplot);

    Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 },
            0);
    for (XYDataItem item : (List<XYDataItem>) series.getItems()) {
        double x = item.getX().doubleValue();
        double y = item.getY().doubleValue();
        double z = (x + y) / 2;
        XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue);
        xyplot.addAnnotation(score);
    }

    //        // put legend inside plot
    //        LegendTitle lt = new LegendTitle(xyplot);
    //        lt.setItemFont(theme.getSmallFont());
    //        lt.setPosition(RectangleEdge.RIGHT);
    //        lt.setItemFont(theme.getSmallFont());
    //        XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT);
    //        ta.setMaxWidth(0.48);
    //        xyplot.addAnnotation(ta);

    // draw guessing line
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse = makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation stroketext = new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);

    ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false,
            false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    //      f.setVisible(true);
    return chart;
}

From source file:org.ow2.clif.jenkins.chart.MovingStatChart.java

@Override
protected JFreeChart createChart() {
    XYSeriesCollection coreDataset = new XYSeriesCollection();
    coreDataset.addSeries(this.eventSerie);

    long periodMs = this.chartConfiguration.getStatisticalPeriod() * 1000L;

    XYSeriesCollection movingDataset = calculateMovingDataset(coreDataset, periodMs);
    XYSeriesCollection throughputDataset = calculateThroughputDataset(coreDataset, periodMs);

    JFreeChart chart;//from  ww w.java 2s  . c o  m
    chart = ChartFactory
            .createXYLineChart(
                    getBasicTitle() + " "
                            + Messages.MovingChart_StatisticalPeriod(
                                    this.chartConfiguration.getStatisticalPeriod()),
                    // chart title
                    Messages.MovingChart_Time(), // x axis label
                    Messages.MovingChart_ResponseTime(), // y axis label
                    movingDataset, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // tooltips
                    false // urls
    );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    configureBasicPlotProperties(plot);

    // Force the 0 on vertical axis
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Force the 0 on horizontal axis
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(true);

    attachThroughputDatasetToDedicatedAxis(throughputDataset, plot);

    // Global renderer for moving stats
    plot.setRenderer(getGlobalRenderer());

    // Dedicated Throughput renderer
    plot.setRenderer(1, getThroughputRenderer());

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo5.java

protected JFreeChart createChart(IntervalXYDataset dataset) {
    domainLabel = "Row_Number";
    rangeLabel = "Frequency";

    JFreeChart chart = ChartFactory.createXYBarChart(chartTitle, domainLabel, false, rangeLabel, dataset,
            PlotOrientation.VERTICAL, false, //!legendPanelOn,
            true, false);/*from   w ww.  j a  v  a 2 s .c om*/

    // then customise it a little...
    // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do"));
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new ClusteredXYBarRenderer());
    XYItemRenderer renderer = plot.getRenderer();

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

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.SuperBubbleChart.java

/**
 * Creates a chart.//from   ww w .  j a v  a 2 s  .c  o m
 * 
 * @param dataset  the dataset.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYZDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBubbleChart(chartTitle, // chart titl                          
            rangeLabel, // y axis label
            domainLabel, // x axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setLegendItemLabelGenerator(new SOCRXYZSeriesLabelGenerator());

    // increase the margins to account for the fact that the auto-range 
    // doesn't take into account the bubble size...
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setLowerMargin(0.15);
    domainAxis.setUpperMargin(0.15);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);

    return chart;
}

From source file:gov.nih.nci.cma.web.graphing.CMAPrincipalComponentAnalysisPlot.java

/**
 * This chart uses the XYAnnotation as a glyph to represent
 * a single pca data point. Glyph shape is determined by survival time.
 * Survival of more than 10 months is represented by a circle. 10 months or less
 * is represented by a square. Component1 values are represented by X
 * Component2 values are represented by Y
 *//*www  .  j  a v a  2  s  .com*/

private void createGlyphsAndAddToPlot(XYPlot plot) { //, double glyphScaleFactor) {
    XYShapeAnnotation glyph;
    Shape glyphShape = null;
    Color glyphColor;
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    Range r = domainAxis.getRange();
    double upperBound = r.getUpperBound();

    double dotSize = 0.7;
    if (upperBound >= 50 && upperBound <= 100)
        dotSize = 1d;
    else if (upperBound > 100 && upperBound <= 150)
        dotSize = 2d;
    else if (upperBound > 150 && upperBound <= 200)
        dotSize = 3d;
    else if (upperBound > 200)
        dotSize = 5d;

    //PrincipalComponentAnalysisDataPoint pcaPoint;
    double x, y;
    //for (Iterator i=dataPoints.iterator(); i.hasNext(); ) {
    for (CMAPCADataPoint pcaPoint : dataPoints) {
        x = pcaPoint.getComponentValue(component1);
        y = pcaPoint.getComponentValue(component2);

        String sampleGroupName = pcaPoint.getSampleGroupName();
        String order = sampleGroupNames.get(sampleGroupName);
        glyphShape = getShapeForDataPoint(order, x, y, dotSize);

        glyphColor = colorMap.get(order);
        if (glyphColor == null)
            glyphColor = Color.black;
        glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor);
        String tooltip = "";

        tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getSampleGroupName();

        glyph.setToolTipText(tooltip);
        plot.addAnnotation(glyph);
    }
}

From source file:carfuzzy.Operations.java

public JFreeChart drawAggregation(FIS[] fis) {

    XYSeriesCollection aggregationDataset = new XYSeriesCollection();
    for (int i = 0; i < 4; i++) {
        aggregationDataset.addSeries(fis[i].getImplication());
    }/*from www . ja  v  a2 s  . com*/
    //aggregationDataset.getSeries(0).setKey("Agjujugregation");
    JFreeChart chart = setToChart(aggregationDataset, "Aggregation");

    XYPlot plot = chart.getXYPlot();
    XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setSeriesVisibleInLegend(false, true);
    renderer.setSeriesItemLabelsVisible(0, false, true);
    renderer.setSeriesItemLabelsVisible(3, true);
    renderer.setPaint(Color.RED.darker(), true);
    plot.setRenderer(renderer);
    ValueAxis xaxis = plot.getDomainAxis();
    xaxis.setRange(0, 10);
    return chart;
}

From source file:com.itemanalysis.jmetrik.graph.irt.IrtPlotPanel.java

private void createChart(String name, String title, String xLabel, String yLabel, double minScore,
        double maxScore) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xLabel, // x axis label
            yLabel, // y axis label
            dataset, // data
            chartOrientation, // chart orientation
            showLegend, // include legend
            true, // tooltips
            false // urls
    );/* w  ww. j a  v a2s . co m*/

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesFilled(false);
    renderer.setDrawOutlines(true);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

    plot.getDomainAxis().setRange(minScore, maxScore);

    ChartPanel panel = new ChartPanel(chart);
    panel.getPopupMenu().addSeparator();
    panel.setPreferredSize(new Dimension(width, height));

    //        this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions

    chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
    charts.put(name, chart);

    JPanel subPanel = new JPanel();//additional panel needed to prevent gridlayout from stretching graph
    subPanel.add(panel);
    //        this.addJpgMenuItem(subPanel, panel.getPopupMenu());
    subPanel.setBackground(Color.WHITE);
    this.add(subPanel);

}