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

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

Introduction

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

Prototype

public ValueAxis getRangeAxis() 

Source Link

Document

Returns the range axis for the plot.

Usage

From source file:playground.artemc.analysis.AnalysisControlerListener.java

private void writeGraphDiv(String name, String yLabel, Map<Integer, Double> it2Double1,
        Map<Integer, Double> it2Double2) {

    XYLineChart chart = new XYLineChart(name, "Iteration", yLabel);

    double[] xValues = new double[it2Double1.size()];
    double[] yValues = new double[it2Double1.size()];
    int counter = 0;
    for (Integer iteration : it2Double1.keySet()) {
        xValues[counter] = iteration.doubleValue();
        yValues[counter] = (it2Double1.get(iteration)) / (it2Double2.get(iteration));
        counter++;/*  w  ww  .  java 2 s  .  c o  m*/
    }

    chart.addSeries(name, xValues, yValues);

    XYPlot plot = chart.getChart().getXYPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRange(true);
    axis.setAutoRangeIncludesZero(false);

    String outputFile = this.scenario.getConfig().controler().getOutputDirectory() + "/" + name + ".png";
    chart.saveAsPng(outputFile, 1000, 800); // File Export
}

From source file:SciTK.PlotXYZBlock.java

private void init(String x_label, String y_label, String window_title) {
    chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true,
            false);/*  ww w  . j a  v  a2  s . co  m*/

    // turn off borders of the plot:
    XYPlot p = chart.getXYPlot();
    p.getDomainAxis().setLowerMargin(0.0);
    p.getDomainAxis().setUpperMargin(0.0);
    p.getRangeAxis().setLowerMargin(0.0);
    p.getRangeAxis().setUpperMargin(0.0);

    // --------------------------------------------
    //          set up a lookup table
    // --------------------------------------------
    // this is how we render the block plots:
    XYBlockRenderer renderer = new XYBlockRenderer();
    // need to find max and min z of the data set:
    double min = 0;
    double max = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) // iterate over data sets
    {
        for (int j = 0; j < data.getItemCount(i); j++) // iterate over points in dataset
        {
            if (data.getZValue(i, j) < min)
                min = data.getZValue(i, j);
            else if (data.getZValue(i, j) > max)
                max = data.getZValue(i, j);
        }
    }
    // create paint scale using min and max values, default color black:
    LookupPaintScale paintScale = new LookupPaintScale(min, max, Color.black);
    // set up the LUT:
    double step_size = (max - min) / 255.; // step size for LUT
    for (int i = 0; i < 256; i++) {
        paintScale.add(min + i * step_size, new Color(i, i, i, 255));
    }
    renderer.setPaintScale(paintScale);
    // set this renderer to the plot:
    p.setRenderer(renderer);

    // --------------------------------------------
    //          set up a color bar
    // --------------------------------------------
    // create an array of display labels:
    num_labels = 10; // default to 10 labels on color bar
    double display_step_size = (max - min) / ((double) num_labels);
    String[] scale_bar_labels = new String[num_labels + 1];
    // to format numbers in scientific notation:
    DecimalFormat formater = new DecimalFormat("0.#E0");
    // create list of labesl:
    for (int i = 0; i <= num_labels; i++) {
        scale_bar_labels[i] = formater.format(min + i * display_step_size);
    }
    // create axis:
    SymbolAxis scaleAxis = new SymbolAxis(null, scale_bar_labels);
    scaleAxis.setRange(min, max);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);
    // set up the paint scale:
    psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setBackgroundPaint(new Color(255, 255, 255, 0)); // clear background
    // set up frame with buffer region to allow text display
    psl.setFrame(new LineBorder((Paint) Color.BLACK, new BasicStroke((float) 1.0),
            new RectangleInsets(15, 10, 15, 10)));
    psl.setAxisOffset(5.0);
    // display on right side:
    psl.setPosition(RectangleEdge.RIGHT);
    // margin around color scale:
    psl.setMargin(new RectangleInsets(20, 15, 20, 15));
    // add to the chart so it will be displayed by default:
    chart.addSubtitle(psl);

    // --------------------------------------------
    //          WINDOW-RELATED UI
    // --------------------------------------------
    // set up the generic plot UI:
    super.window_title = window_title;
    super.initUI();

    // add another menu item
    JMenuBar mb = super.getJMenuBar(); // get the menu bar
    // find menu named "Plot"
    JMenu menu_plot = null;
    for (int i = 0; i < mb.getMenuCount(); i++) {
        if (mb.getMenu(i).getText() == "Plot")
            menu_plot = mb.getMenu(i);
    }
    // Add a new checkbox for the color scale bar
    JCheckBoxMenuItem menu_plot_scalebar = new JCheckBoxMenuItem("Color Scale");
    menu_plot_scalebar.setToolTipText("Show color scale bar?");
    menu_plot_scalebar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            setScaleBar(selected);
        }
    });
    // set appropirate checkbox state:
    menu_plot_scalebar.setState(true);
    if (menu_plot != null) // sanity check
        menu_plot.add(menu_plot_scalebar);

}

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

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

    chart.setBackgroundPaint(Color.white);

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

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

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

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

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

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

From source file:playground.christoph.evacuation.analysis.AgentsInMunicipalityEventsHandler.java

private JFreeChart getGraphic() {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries insideSerie = new XYSeries("total inside area", false, true);
    final XYSeries residentsSerie = new XYSeries("residents inside area", false, true);
    final XYSeries commutersSerie = new XYSeries("commuters inside area", false, true);

    for (int i = 0; i < plotData.size(); i++) {
        PlotData pd = plotData.get(i);//  w  w  w .ja  va  2  s .co  m
        double hour = pd.time / 3600.0;
        insideSerie.add(hour, pd.commuterAgentCount + pd.residentAgentCount);
        residentsSerie.add(hour, pd.residentAgentCount);
        commutersSerie.add(hour, pd.commuterAgentCount);
    }
    xyData.addSeries(insideSerie);
    xyData.addSeries(residentsSerie);
    xyData.addSeries(commutersSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart("agents inside area", "time [hour]", "# agents",
            xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    NumberAxis na = new NumberAxis("time [hour]");
    na.setRange(0, maxTime / 3600.0);
    na.setLabelFont(plot.getRangeAxis().getLabelFont());
    na.setTickLabelFont(plot.getRangeAxis().getTickLabelFont());
    plot.setDomainAxis(na);
    return chart;
}

From source file:ac.openmicrolabs.view.gui.OMLLoggerView.java

@Override
public final void setViewLoggingCompleted(final double graphTimeRange) {
    final XYPlot plot = snsChart.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);//from  ww w .j  a va2  s .co  m
    axis.setFixedAutoRange(graphTimeRange);
    axis = plot.getRangeAxis();
    axis.setRange(graphMinY, graphMaxY);

    this.setTitle(OMLAppDetails.name());

    valSideLabel.setText(h.format("label-bold", avgSideLabel.getText()));
    avgSideLabel.setText("");
    for (int i = 0; i < avgLabel.length; i++) {
        valLabel[i].setText(h.format("label-bold", h.get("body").unformat(avgLabel[i].getText())));
        avgLabel[i].setText("");
    }

    reportButton.setSize(doneButton.getSize());
    reportButton.setIcon(new ImageIcon("img/22x22/save.png"));
    reportButton.setLocation(doneButton.getX() - doneButton.getWidth() - PAD10, doneButton.getY());
    reportButton.setBackground(Color.white);

    footerLabel.setSize(reportButton.getLocation().x, PAD30);
    footerLabel.setHorizontalAlignment(JLabel.CENTER);

    btmPanel.remove(progressBar);
    btmPanel.add(reportButton);
    btmPanel.repaint();
    doneButton.setText("Done");
    doneButton.setIcon(new ImageIcon("img/22x22/play.png", OMLAppDetails.name()));
}

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

/**
 * Creates a chart./*from   w  ww . j a va 2 s.co  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYAreaChart("XY Area Chart Demo", "Domain (X)", "Range (Y)",
            dataset, PlotOrientation.VERTICAL, true, // legend
            true, // tool tips
            false // URLs
    );

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    //plot.setOutlinePaint(Color.black);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setForegroundAlpha(0.65f);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickMarkPaint(Color.black);

    return chart;

}

From source file:charts.Chart.java

public static void GraficoSeries() {
    //System.out.println("After initComponents");

    JFrame janela = new JFrame("Example of the series graphic");
    janela.getContentPane().setLayout(null);

    javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
    jLabel1.setText("");
    janela.getContentPane().add(jLabel1);

    y_of_x = new double[n_points];
    x = new double[n_points];

    XYSeries series1 = new XYSeries("Cos(x) versus x");
    XYSeries series2 = new XYSeries("Cos^2(x) versus x");

    for (int i = 0; i < n_points; i++) {//calculate the data to be plotted

        y_of_x[i] = Math.cos(i * Math.PI / 180);
        series1.add((double) i, y_of_x[i]);//add values to the series

        series2.add((double) i, Math.pow(y_of_x[i], 2));
    }/*from   w  ww . j av a  2s  .  c o m*/

    XYDataset dataset1 = new XYSeriesCollection(series1);
    XYDataset dataset2 = new XYSeriesCollection(series2);

    CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new NumberAxis("x-angle argument"));

    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    XYPlot subplot1 = new XYPlot(dataset1, null, new NumberAxis("Cos(x)"), renderer1);
    NumberAxis axis1 = (NumberAxis) subplot1.getRangeAxis();
    axis1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 10));
    axis1.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    axis1.setAutoRangeIncludesZero(false);
    parent.add(subplot1, 1);

    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    XYPlot subplot2 = new XYPlot(dataset2, null, new NumberAxis("Cos^2(x)"), renderer2);
    NumberAxis axis2 = (NumberAxis) subplot2.getRangeAxis();
    axis2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 10));
    axis2.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    axis2.setAutoRangeIncludesZero(false);
    parent.add(subplot2, 1);

    JFreeChart chart = new JFreeChart("Cos(x) versus x", parent);

    ChartPanel myChart = new ChartPanel(chart);
    janela.setSize(500, 600);
    janela.setContentPane(myChart);

    janela.setVisible(true);
}

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

/**
 * Creates a chart.//w w  w  .  j a va  2 s . c o m
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYAreaChart(chartTitle, "Domain (X)", "Range (Y)", dataset,
            PlotOrientation.VERTICAL, !legendPanelOn, // legend
            true, // tool tips
            false // URLs
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setForegroundAlpha(0.65f);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickMarkPaint(Color.black);

    /*  XYPointerAnnotation pointer = new XYPointerAnnotation(
    "Test", 5.0, -500.0, 3.0 * Math.PI / 4.0
      );
      pointer.setTipRadius(0.0); 
      pointer.setBaseRadius(35.0); 
      pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); 
      pointer.setPaint(Color.blue); 
      pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); 
      plot.addAnnotation(pointer);*/

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    setXSummary(dataset);
    return chart;

}

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

@Override
protected JFreeChart generateChart(WCChartTheme chartTheme) {
    setChartHeight(36);// ww  w .  j a  v a  2 s . c om

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(null, null, yAxisLabel(), boxAndWhiskerXYDataset(),
            false);
    chart.getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    chart.setPadding(new RectangleInsets(0, 6, 0, 6));

    XYPlot plot = chart.getXYPlot();
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(new Color(0, 0, 0, 0));
    XYBoxAndWhiskerRenderer renderer = (XYBoxAndWhiskerRenderer) plot.getRenderer();
    renderer.setAutoPopulateSeriesOutlinePaint(true);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(-0.5, assignmentOffering.assignment().submissionProfile().availablePoints() + 0.5);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    Font oldFont = rangeAxis.getTickLabelFont();
    rangeAxis.setTickLabelFont(oldFont.deriveFont(oldFont.getSize2D() * 0.8f));

    return chart;
}

From source file:com.sciaps.view.PlotConfigPanel.java

/**
 * Creates new form PlotRangeSetterPanel
 *
 * @param plot//from  w  w  w. j  a  v  a  2 s.c o  m
 */
public PlotConfigPanel(XYPlot plot) {
    initComponents();

    plot_ = plot;
    rangeAxis_ = plot.getRangeAxis();
    domainAxis_ = plot.getDomainAxis();

    btnLeft_.setIcon(createImageIcon("/images/left.png"));
    btnRight_.setIcon(createImageIcon("/images/right.png"));
    btnAutoRange_.setIcon(createImageIcon("/images/center.png"));
    btnUp_.setIcon(createImageIcon("/images/up.png"));
    btnDown_.setIcon(createImageIcon("/images/down.png"));

    mousePressed_ = false;
}