Example usage for org.jfree.chart.axis NumberAxis setAutoRange

List of usage examples for org.jfree.chart.axis NumberAxis setAutoRange

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setAutoRange.

Prototype

public void setAutoRange(boolean auto) 

Source Link

Document

Sets a flag that determines whether or not the axis range is automatically adjusted to fit the data, and notifies registered listeners that the axis has been modified.

Usage

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java

private static JFreeChart createTimeSeriesChart() {
    XYDataset dataset1 = createDataset1();
    //DomainAxis/*w  w w.  j  ava2  s  .  co m*/
    DateAxis timeAxis = new DateAxis("");
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));
    //RangeAxis
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    NumberAxis valueAxis2 = new NumberAxis("");
    valueAxis2.setAutoRangeIncludesZero(false); // override default
    //        valueAxis.setDefaultAutoRange(new Range(100, 1150));
    //Renderer
    XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);
    XYDataset dataset2 = createDataset2();
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    //Plot
    XYPlot plot = new XYPlot(dataset1, timeAxis, valueAxis, null);
    plot.setRenderer(renderer);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setRangeAxis(1, valueAxis2);
    plot.mapDatasetToRangeAxis(1, 1);
    plot.setBackgroundPaint(plotBackgroundPaint);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    //        plot.setRangePannable(true);
    //chart
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    valueAxis.setAutoRange(false);
    timeAxis.setAutoRange(false);
    return chart;
}

From source file:org.jax.pubarray.server.restful.GraphingResource.java

/**
 * Create a graph for the given configuration
 * @param graphConfiguration//from w  ww .  ja  va  2  s. c  om
 *          the key
 * @return
 *          the graph
 */
@SuppressWarnings("unchecked")
private JFreeChart createProbeIntensityGraph(ProbeIntensityGraphConfiguration graphConfiguration) {
    try {
        Connection connection = this.getConnection();

        String[] probeIds = graphConfiguration.getProbeIds();
        double[][] probeDataRows = new double[probeIds.length][];
        for (int i = 0; i < probeIds.length; i++) {
            probeDataRows[i] = this.persistenceManager.getDataRowForProbeID(connection, probeIds[i]);
        }

        TableColumnMetadata orderBy = graphConfiguration.getOrderProbesBy();
        final List<Comparable> orderByItems;
        if (orderBy != null) {
            LOG.info("We are ordering by: " + orderBy);
            orderByItems = this.persistenceManager.getDesignDataColumn(connection, orderBy);
        } else {
            orderByItems = null;
        }

        TableMetadata metadata = this.persistenceManager.getDataTableMetadata(connection);
        final CategoryDataset categoryDataset;
        if (graphConfiguration.getGroupReplicates()) {
            switch (graphConfiguration.getGroupedGraphType()) {
            case BOX_PLOT: {
                categoryDataset = new DefaultBoxAndWhiskerCategoryDataset();
            }
                break;

            case SCATTER_PLOT: {
                categoryDataset = new DefaultMultiValueCategoryDataset();
            }
                break;

            default:
                throw new IllegalArgumentException(
                        "don't know how to deal with plot type: " + graphConfiguration.getGroupedGraphType());
            }
        } else {
            categoryDataset = new DefaultCategoryDataset();
        }

        // iterate through all of the selected probesets
        List<QualifiedColumnMetadata> termsOfInterest = Arrays.asList(graphConfiguration.getTermsOfInterest());
        for (int rowIndex = 0; rowIndex < probeDataRows.length; rowIndex++) {
            double[] currRow = probeDataRows[rowIndex];
            assert currRow.length == metadata.getColumnMetadata().length - 1;

            // should we log2 transform the data?
            if (graphConfiguration.getLog2TransformData()) {
                for (int i = 0; i < currRow.length; i++) {
                    currRow[i] = Math.log(currRow[i]) / LOG2_FACTOR;
                }
            }

            // iterate through the columns in the data table (each column
            // represents a different array)
            List<ComparableContainer<Double, Comparable>> rowElemList = new ArrayList<ComparableContainer<Double, Comparable>>();
            for (int colIndex = 0; colIndex < currRow.length; colIndex++) {
                // we use +1 indexing here because we want to skip over
                // the probesetId metadata and get right to the
                // array intensity metadata
                TableColumnMetadata colMeta = metadata.getColumnMetadata()[colIndex + 1];

                // check to see if we need to skip this data
                if (!graphConfiguration.getIncludeDataFromAllArrays()) {
                    // if it's one of the "terms of interest" we will keep
                    // it. we're using a brute force search here
                    boolean keepThisOne = false;
                    for (QualifiedColumnMetadata termOfInterest : termsOfInterest) {
                        if (termOfInterest.getTableName().equals(metadata.getTableName())
                                && termOfInterest.getName().equals(colMeta.getName())) {
                            keepThisOne = true;
                            break;
                        }
                    }

                    if (!keepThisOne) {
                        continue;
                    }
                }

                final String columnName = colMeta.getName();
                final Comparable columnKey;
                if (orderByItems == null) {
                    columnKey = columnName;
                } else {
                    // the ordering will be done on the selected
                    // "order by" design criteria
                    columnKey = new ComparableContainer<String, Comparable>(columnName,
                            orderByItems.get(colIndex), !graphConfiguration.getGroupReplicates());

                    // TODO remove me!!!!
                    System.out.println("For array " + columnName + " the order by " + "value is: "
                            + orderByItems.get(colIndex));
                    // end of remove me
                }

                rowElemList
                        .add(new ComparableContainer<Double, Comparable>(currRow[colIndex], columnKey, false));
            }

            Collections.sort(rowElemList);

            if (graphConfiguration.getGroupReplicates()) {
                switch (graphConfiguration.getGroupedGraphType()) {
                case BOX_PLOT: {
                    DefaultBoxAndWhiskerCategoryDataset dataset = (DefaultBoxAndWhiskerCategoryDataset) categoryDataset;
                    for (int i = 0; i < rowElemList.size(); i++) {
                        List<Double> groupList = new ArrayList<Double>();
                        groupList.add(rowElemList.get(i).getElement());
                        Comparable colKey = rowElemList.get(i).getComparable();

                        i++;
                        for (; i < rowElemList.size()
                                && rowElemList.get(i).getComparable().equals(colKey); i++) {
                            groupList.add(rowElemList.get(i).getElement());
                        }
                        i--;

                        dataset.add(groupList, probeIds[rowIndex], colKey);
                    }
                }
                    break;

                case SCATTER_PLOT: {
                    DefaultMultiValueCategoryDataset dataset = (DefaultMultiValueCategoryDataset) categoryDataset;
                    for (int i = 0; i < rowElemList.size(); i++) {
                        List<Double> groupList = new ArrayList<Double>();
                        groupList.add(rowElemList.get(i).getElement());
                        Comparable colKey = rowElemList.get(i).getComparable();

                        i++;
                        for (; i < rowElemList.size()
                                && rowElemList.get(i).getComparable().equals(colKey); i++) {
                            groupList.add(rowElemList.get(i).getElement());
                        }
                        i--;

                        dataset.add(groupList, probeIds[rowIndex], colKey);
                    }
                }
                    break;
                }
            } else {
                DefaultCategoryDataset dataset = (DefaultCategoryDataset) categoryDataset;
                for (ComparableContainer<Double, Comparable> rowElem : rowElemList) {
                    dataset.addValue(rowElem.getElement(), probeIds[rowIndex], rowElem.getComparable());
                }
            }
        }

        CategoryAxis xAxis = new CategoryAxis();
        if (graphConfiguration.getGroupReplicates() && orderBy != null) {
            xAxis.setLabel(orderBy.getName());
        } else {
            if (orderBy != null) {
                xAxis.setLabel("Arrays (Ordered By " + orderBy.getName() + ")");
            } else {
                xAxis.setLabel("Arrays");
            }
        }
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

        final NumberAxis yAxis;
        if (graphConfiguration.getLog2TransformData()) {
            yAxis = new NumberAxis("log2(Intensity)");
        } else {
            yAxis = new NumberAxis("Intensity");
        }
        yAxis.setAutoRange(true);
        yAxis.setAutoRangeIncludesZero(false);

        // TODO: this is a HACK to deal with auto-range bug in JFreeChart
        //       which occurs when doing the grouped scatter plot
        if (graphConfiguration.getGroupReplicates()
                && graphConfiguration.getGroupedGraphType() == GroupedGraphType.SCATTER_PLOT) {
            double minVal = Double.POSITIVE_INFINITY;
            double maxVal = Double.NEGATIVE_INFINITY;
            for (double[] dataRow : probeDataRows) {
                for (double datum : dataRow) {
                    if (datum > maxVal) {
                        maxVal = datum;
                    }

                    if (datum < minVal) {
                        minVal = datum;
                    }
                }

                if (minVal != Double.POSITIVE_INFINITY && maxVal != Double.NEGATIVE_INFINITY
                        && minVal != maxVal) {
                    yAxis.setAutoRange(false);

                    double margin = (maxVal - minVal) * 0.02;
                    Range yRange = new Range(minVal - margin, maxVal + margin);
                    yAxis.setRange(yRange);
                }
            }
        }
        // END HACK

        final CategoryItemRenderer renderer;
        if (graphConfiguration.getGroupReplicates()) {
            switch (graphConfiguration.getGroupedGraphType()) {
            case BOX_PLOT: {
                BoxAndWhiskerRenderer boxRenderer = new BoxAndWhiskerRenderer();
                boxRenderer.setMaximumBarWidth(0.03);
                renderer = boxRenderer;
            }
                break;

            case SCATTER_PLOT: {
                renderer = new ScatterRenderer();
            }
                break;

            default:
                throw new IllegalArgumentException(
                        "don't know how to deal with plot type: " + graphConfiguration.getGroupedGraphType());
            }
        } else {
            renderer = new LineAndShapeRenderer();
        }
        Plot plot = new CategoryPlot(categoryDataset, xAxis, yAxis, renderer);

        return new JFreeChart("Intensity Values", plot);
    } catch (SQLException ex) {
        LOG.log(Level.SEVERE, "failed to generate image", ex);
        return null;
    }
}

From source file:com.vgi.mafscaling.MafCompare.java

/**
 * Initialize the contents of the frame.
 *///from  ww w  . j  a  v a 2  s . c o m
private void initialize() {
    try {
        ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg"));
        setTitle(Title);
        setIconImage(tableImage.getImage());
        setBounds(100, 100, 621, 372);
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        setSize(Config.getCompWindowSize());
        setLocation(Config.getCompWindowLocation());
        setLocationRelativeTo(null);
        setVisible(false);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                Utils.clearTable(origMafTable);
                Utils.clearTable(newMafTable);
                Utils.clearTable(compMafTable);
                Config.setCompWindowSize(getSize());
                Config.setCompWindowLocation(getLocation());
                origMafData.clear();
                newMafData.clear();
            }
        });

        JPanel dataPanel = new JPanel();
        GridBagLayout gbl_dataPanel = new GridBagLayout();
        gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 };
        gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 };
        gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 };
        gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
        dataPanel.setLayout(gbl_dataPanel);
        getContentPane().add(dataPanel);

        JLabel origLabel = new JLabel(origMaf);
        GridBagConstraints gbc_origLabel = new GridBagConstraints();
        gbc_origLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origLabel.weightx = 0;
        gbc_origLabel.weighty = 0;
        gbc_origLabel.gridx = 0;
        gbc_origLabel.gridy = 0;
        gbc_origLabel.gridheight = 2;
        dataPanel.add(origLabel, gbc_origLabel);

        JLabel newLabel = new JLabel(newMaf);
        GridBagConstraints gbc_newLabel = new GridBagConstraints();
        gbc_newLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newLabel.weightx = 0;
        gbc_newLabel.weighty = 0;
        gbc_newLabel.gridx = 0;
        gbc_newLabel.gridy = 2;
        gbc_newLabel.gridheight = 2;
        dataPanel.add(newLabel, gbc_newLabel);

        JLabel compLabel = new JLabel("Change");
        GridBagConstraints gbc_compLabel = new GridBagConstraints();
        gbc_compLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_compLabel.insets = new Insets(1, 1, 1, 5);
        gbc_compLabel.weightx = 0;
        gbc_compLabel.weighty = 0;
        gbc_compLabel.gridx = 0;
        gbc_compLabel.gridy = 4;
        dataPanel.add(compLabel, gbc_compLabel);

        JLabel origVoltLabel = new JLabel("volt");
        GridBagConstraints gbc_origVoltLabel = new GridBagConstraints();
        gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origVoltLabel.weightx = 0;
        gbc_origVoltLabel.weighty = 0;
        gbc_origVoltLabel.gridx = 1;
        gbc_origVoltLabel.gridy = 0;
        dataPanel.add(origVoltLabel, gbc_origVoltLabel);

        JLabel origGsLabel = new JLabel(" g/s");
        GridBagConstraints gbc_origGsLabel = new GridBagConstraints();
        gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origGsLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origGsLabel.weightx = 0;
        gbc_origGsLabel.weighty = 0;
        gbc_origGsLabel.gridx = 1;
        gbc_origGsLabel.gridy = 1;
        dataPanel.add(origGsLabel, gbc_origGsLabel);

        JLabel newVoltLabel = new JLabel("volt");
        GridBagConstraints gbc_newVoltLabel = new GridBagConstraints();
        gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newVoltLabel.weightx = 0;
        gbc_newVoltLabel.weighty = 0;
        gbc_newVoltLabel.gridx = 1;
        gbc_newVoltLabel.gridy = 2;
        dataPanel.add(newVoltLabel, gbc_newVoltLabel);

        JLabel newGsLabel = new JLabel(" g/s");
        GridBagConstraints gbc_newGsLabel = new GridBagConstraints();
        gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newGsLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newGsLabel.weightx = 0;
        gbc_newGsLabel.weighty = 0;
        gbc_newGsLabel.gridx = 1;
        gbc_newGsLabel.gridy = 3;
        dataPanel.add(newGsLabel, gbc_newGsLabel);

        JLabel compPctLabel = new JLabel(" %  ");
        GridBagConstraints gbc_compPctLabel = new GridBagConstraints();
        gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_compPctLabel.insets = new Insets(1, 1, 1, 5);
        gbc_compPctLabel.weightx = 0;
        gbc_compPctLabel.weighty = 0;
        gbc_compPctLabel.gridx = 1;
        gbc_compPctLabel.gridy = 4;
        dataPanel.add(compPctLabel, gbc_compPctLabel);

        JPanel tablesPanel = new JPanel();
        GridBagLayout gbl_tablesPanel = new GridBagLayout();
        gbl_tablesPanel.columnWidths = new int[] { 0 };
        gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 };
        gbl_tablesPanel.columnWeights = new double[] { 0.0 };
        gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 };
        tablesPanel.setLayout(gbl_tablesPanel);

        JScrollPane mafScrollPane = new JScrollPane(tablesPanel);
        mafScrollPane.setMinimumSize(new Dimension(1600, 107));
        mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20));
        mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        GridBagConstraints gbc_mafScrollPane = new GridBagConstraints();
        gbc_mafScrollPane.weightx = 1.0;
        gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START;
        gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL;
        gbc_mafScrollPane.gridx = 2;
        gbc_mafScrollPane.gridy = 0;
        gbc_mafScrollPane.gridheight = 5;
        dataPanel.add(mafScrollPane, gbc_mafScrollPane);

        origMafTable = new JTable();
        origMafTable.setColumnSelectionAllowed(true);
        origMafTable.setCellSelectionEnabled(true);
        origMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        origMafTable.setRowHeight(RowHeight);
        origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
        origMafTable.setTableHeader(null);
        Utils.initializeTable(origMafTable, ColumnWidth);
        GridBagConstraints gbc_origMafTable = new GridBagConstraints();
        gbc_origMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_origMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_origMafTable.weightx = 1.0;
        gbc_origMafTable.weighty = 0;
        gbc_origMafTable.gridx = 0;
        gbc_origMafTable.gridy = 0;
        tablesPanel.add(origMafTable, gbc_origMafTable);
        excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true);

        newMafTable = new JTable();
        newMafTable.setColumnSelectionAllowed(true);
        newMafTable.setCellSelectionEnabled(true);
        newMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        newMafTable.setRowHeight(RowHeight);
        newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
        newMafTable.setTableHeader(null);
        Utils.initializeTable(newMafTable, ColumnWidth);
        GridBagConstraints gbc_newMafTable = new GridBagConstraints();
        gbc_newMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_newMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_newMafTable.weightx = 1.0;
        gbc_newMafTable.weighty = 0;
        gbc_newMafTable.gridx = 0;
        gbc_newMafTable.gridy = 1;
        tablesPanel.add(newMafTable, gbc_newMafTable);
        excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true);

        compMafTable = new JTable();
        compMafTable.setColumnSelectionAllowed(true);
        compMafTable.setCellSelectionEnabled(true);
        compMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        compMafTable.setRowHeight(RowHeight);
        compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount));
        compMafTable.setTableHeader(null);
        Utils.initializeTable(compMafTable, ColumnWidth);
        NumberFormatRenderer numericRenderer = new NumberFormatRenderer();
        numericRenderer.setFormatter(new DecimalFormat("0.000"));
        compMafTable.setDefaultRenderer(Object.class, numericRenderer);
        GridBagConstraints gbc_compMafTable = new GridBagConstraints();
        gbc_compMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_compMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_compMafTable.weightx = 1.0;
        gbc_compMafTable.weighty = 0;
        gbc_compMafTable.gridx = 0;
        gbc_compMafTable.gridy = 2;
        tablesPanel.add(compMafTable, gbc_compMafTable);
        compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true);

        TableModelListener origTableListener = new TableModelListener() {
            public void tableChanged(TableModelEvent tme) {
                if (tme.getType() == TableModelEvent.UPDATE) {
                    int colCount = origMafTable.getColumnCount();
                    Utils.ensureColumnCount(colCount, newMafTable);
                    Utils.ensureColumnCount(colCount, compMafTable);
                    origMafData.clear();
                    String origY, origX, newY;
                    for (int i = 0; i < colCount; ++i) {
                        origY = origMafTable.getValueAt(1, i).toString();
                        if (Pattern.matches(Utils.fpRegex, origY)) {
                            origX = origMafTable.getValueAt(0, i).toString();
                            if (Pattern.matches(Utils.fpRegex, origX))
                                origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false);
                            newY = newMafTable.getValueAt(1, i).toString();
                            if (Pattern.matches(Utils.fpRegex, newY))
                                compMafTable.setValueAt(
                                        ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
                        } else
                            break;
                    }
                    origMafData.fireSeriesChanged();
                }
            }
        };

        TableModelListener newTableListener = new TableModelListener() {
            public void tableChanged(TableModelEvent tme) {
                if (tme.getType() == TableModelEvent.UPDATE) {
                    int colCount = newMafTable.getColumnCount();
                    Utils.ensureColumnCount(colCount, origMafTable);
                    Utils.ensureColumnCount(colCount, compMafTable);
                    newMafData.clear();
                    String newY, newX, origY;
                    for (int i = 0; i < colCount; ++i) {
                        newY = newMafTable.getValueAt(1, i).toString();
                        if (Pattern.matches(Utils.fpRegex, newY)) {
                            newX = newMafTable.getValueAt(0, i).toString();
                            if (Pattern.matches(Utils.fpRegex, newX))
                                newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false);
                            origY = origMafTable.getValueAt(1, i).toString();
                            if (Pattern.matches(Utils.fpRegex, origY))
                                compMafTable.setValueAt(
                                        ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
                        } else
                            break;
                    }
                    newMafData.fireSeriesChanged();
                }
            }
        };

        origMafTable.getModel().addTableModelListener(origTableListener);
        newMafTable.getModel().addTableModelListener(newTableListener);

        Action action = new AbstractAction() {
            private static final long serialVersionUID = 8148393537657380215L;

            public void actionPerformed(ActionEvent e) {
                TableCellListener tcl = (TableCellListener) e.getSource();
                if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) {
                    if (Pattern.matches(Utils.fpRegex,
                            origMafTable.getValueAt(1, tcl.getColumn()).toString())) {
                        double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString())
                                / 100.0 + 1.0;
                        newMafTable.setValueAt(
                                Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr,
                                1, tcl.getColumn());
                    }
                } else
                    compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn());
            }
        };

        setCompMafCellListener(new TableCellListener(compMafTable, action));

        // CHART

        JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL,
                false, true, false);
        chart.setBorderVisible(true);
        chartPanel = new ChartPanel(chart, true, true, true, true, true);
        chartPanel.setAutoscrolls(true);

        GridBagConstraints gbl_chartPanel = new GridBagConstraints();
        gbl_chartPanel.anchor = GridBagConstraints.PAGE_START;
        gbl_chartPanel.fill = GridBagConstraints.BOTH;
        gbl_chartPanel.insets = new Insets(1, 1, 1, 1);
        gbl_chartPanel.weightx = 1.0;
        gbl_chartPanel.weighty = 1.0;
        gbl_chartPanel.gridx = 0;
        gbl_chartPanel.gridy = 5;
        gbl_chartPanel.gridheight = 1;
        gbl_chartPanel.gridwidth = 3;
        dataPanel.add(chartPanel, gbl_chartPanel);

        XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
        lineRenderer.setUseFillPaint(true);
        lineRenderer.setBaseToolTipGenerator(
                new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        new DecimalFormat("0.00"), new DecimalFormat("0.00")));

        Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
        lineRenderer.setSeriesStroke(0, stroke);
        lineRenderer.setSeriesStroke(1, stroke);
        lineRenderer.setSeriesPaint(0, new Color(201, 0, 0));
        lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
        lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
        lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5));
        lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
            private static final long serialVersionUID = -4045338273187150888L;

            public String generateLabel(XYDataset dataset, int series) {
                XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
                return xys.getDescription();
            }
        });

        NumberAxis mafvDomain = new NumberAxis(XAxisName);
        mafvDomain.setAutoRangeIncludesZero(false);
        mafvDomain.setAutoRange(true);
        mafvDomain.setAutoRangeStickyZero(false);
        NumberAxis mafgsRange = new NumberAxis(YAxisName);
        mafgsRange.setAutoRangeIncludesZero(false);
        mafgsRange.setAutoRange(true);
        mafgsRange.setAutoRangeStickyZero(false);

        XYSeriesCollection lineDataset = new XYSeriesCollection();
        origMafData.setDescription(origMaf);
        newMafData.setDescription(newMaf);
        lineDataset.addSeries(origMafData);
        lineDataset.addSeries(newMafData);

        XYPlot plot = chart.getXYPlot();
        plot.setRangePannable(true);
        plot.setDomainPannable(true);
        plot.setDomainGridlinePaint(Color.DARK_GRAY);
        plot.setRangeGridlinePaint(Color.DARK_GRAY);
        plot.setBackgroundPaint(new Color(224, 224, 224));

        plot.setDataset(0, lineDataset);
        plot.setRenderer(0, lineRenderer);
        plot.setDomainAxis(0, mafvDomain);
        plot.setRangeAxis(0, mafgsRange);
        plot.mapDatasetToDomainAxis(0, 0);
        plot.mapDatasetToRangeAxis(0, 0);

        LegendTitle legend = new LegendTitle(plot.getRenderer());
        legend.setItemFont(new Font("Arial", 0, 10));
        legend.setPosition(RectangleEdge.TOP);
        chart.addLegend(legend);

    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.MarkerScatter.java

public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL,
            false, true, false);/*from w  ww  . jav a  2 s. c o m*/

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    chart.setBackgroundPaint(Color.white);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

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

    XYItemRenderer renderer = plot.getRenderer();

    //defines colors 
    int seriesN = dataset.getSeriesCount();
    if ((colorMap != null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))) {
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getSeriesKey(i);
            Color color = new Color(Integer.decode(defaultColor).intValue());
            if (colorMap != null && colorMap.size() > 0)
                color = (Color) colorMap.get(serieName);
            if (color != null)
                renderer.setSeriesPaint(i, color);
        }
    }

    // add un interval  marker for the Y axis...
    if (yMarkerStartInt != null && yMarkerEndInt != null && !yMarkerStartInt.equals("")
            && !yMarkerEndInt.equals("")) {
        Marker intMarkerY = new IntervalMarker(Double.parseDouble(yMarkerStartInt),
                Double.parseDouble(yMarkerEndInt));
        intMarkerY.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        intMarkerY.setPaint(
                new Color(Integer.decode((yMarkerIntColor.equals("")) ? "0" : yMarkerIntColor).intValue()));
        //intMarkerY.setLabel(yMarkerLabel);
        intMarkerY.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        intMarkerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(intMarkerY, Layer.BACKGROUND);
    }
    // add un interval  marker for the X axis...
    if (xMarkerStartInt != null && xMarkerEndInt != null && !xMarkerStartInt.equals("")
            && !xMarkerEndInt.equals("")) {
        Marker intMarkerX = new IntervalMarker(Double.parseDouble(xMarkerStartInt),
                Double.parseDouble(xMarkerEndInt));
        intMarkerX.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        intMarkerX.setPaint(
                new Color(Integer.decode((xMarkerIntColor.equals("")) ? "0" : xMarkerIntColor).intValue()));
        //intMarkerX.setLabel(xMarkerLabel);
        intMarkerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        intMarkerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addRangeMarker(intMarkerX, Layer.BACKGROUND);
    }
    // add a labelled marker for the Y axis...
    if (yMarkerValue != null && !yMarkerValue.equals("")) {
        Marker markerY = new ValueMarker(Double.parseDouble(yMarkerValue));
        markerY.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        if (!yMarkerColor.equals(""))
            markerY.setPaint(new Color(Integer.decode(yMarkerColor).intValue()));
        markerY.setLabel(yMarkerLabel);
        markerY.setLabelFont(new Font("Arial", Font.BOLD, 11));
        markerY.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        markerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(markerY, Layer.BACKGROUND);
    }
    // add a labelled marker for the X axis...
    if (xMarkerValue != null && !xMarkerValue.equals("")) {
        Marker markerX = new ValueMarker(Double.parseDouble(xMarkerValue));
        markerX.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        if (!xMarkerColor.equals(""))
            markerX.setPaint(new Color(Integer.decode(xMarkerColor).intValue()));
        markerX.setLabel(xMarkerLabel);
        markerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        markerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addRangeMarker(markerX, Layer.BACKGROUND);
    }

    if (xRangeLow != null && !xRangeLow.equals("") && xRangeHigh != null && !xRangeHigh.equals("")) {
        if (Double.valueOf(xRangeLow).doubleValue() > xMin)
            xRangeLow = String.valueOf(xMin);
        if (Double.valueOf(xRangeHigh).doubleValue() < xMax)
            xRangeHigh = String.valueOf(xMax);
        ValueAxis rangeAxis = plot.getRangeAxis();
        //rangeAxis.setRange(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh));
        rangeAxis.setRangeWithMargins(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh));
    } else {
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setAutoRange(true);
        rangeAxis.setRange(xMin, xMax);
    }

    if (yRangeLow != null && !yRangeLow.equals("") && yRangeHigh != null && !yRangeHigh.equals("")) {
        if (Double.valueOf(yRangeLow).doubleValue() > yMin)
            yRangeLow = String.valueOf(yMin);
        if (Double.valueOf(yRangeHigh).doubleValue() < yMax)
            yRangeHigh = String.valueOf(yMax);
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        //domainAxis.setRange(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh));
        domainAxis.setRangeWithMargins(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh));
        domainAxis.setAutoRangeIncludesZero(false);
    } else {
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setAutoRange(true);
        domainAxis.setRange(yMin, yMax);
        domainAxis.setAutoRangeIncludesZero(false);
    }

    //add annotations if requested
    if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")) {
        if (annotationMap == null || annotationMap.size() == 0)
            logger.error("Annotations on the chart are requested but the annotationMap is null!");
        else {
            int cont = 1;
            for (Iterator iterator = annotationMap.keySet().iterator(); iterator.hasNext();) {
                String text = (String) iterator.next();
                String pos = (String) annotationMap.get(text);
                double x = Double.parseDouble(pos.substring(0, pos.indexOf("__")));
                double y = Double.parseDouble(pos.substring(pos.indexOf("__") + 2));
                //default up position
                XYTextAnnotation annotation = new XYTextAnnotation(text, y - 1,
                        x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1));
                if (cont % 2 != 0)
                    //dx
                    annotation = new XYTextAnnotation(text, y,
                            x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1));
                else
                    //sx
                    //annotation = new XYTextAnnotation(text, y, x-((text.length()%2==0)?text.length():text.length()-1));
                    annotation = new XYTextAnnotation(text, y, x - (text.length() - 1));

                annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
                //annotation.setRotationAngle(Math.PI / 4.0);
                annotation.setRotationAngle(0.0); // horizontal
                plot.addAnnotation(annotation);
                cont++;
            }
            renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8));
        }
    } else if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("false")) {
        renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8));
    }
    if (legend == true) {

        drawLegend(chart);
    }
    return chart;
}

From source file:projects.wdlf47tuc.ProcessAllSwathcal.java

/**
 * Computes the luminosity function for the current boxed region and plots it in a JFrame.
 * Also prints out the coordinates of the selection box vertices and the luminosity function
 * quantities./*w  w  w. jav a  2 s  .c om*/
 * 
 * @param sources
 *    The {@link Source}s to compute the luminosity function for.
 */
private void computeAndPlotLuminosityFunction(List<Source> sources) {

    // Print out coordinates of selection box corners
    System.out.println("# Coordinates of selection box corners:");
    System.out.println("# (" + col1Filter + "-" + col2Filter + ")\t" + magFilter);
    for (double[] point : points) {
        System.out.println("# " + point[0] + "\t" + point[1]);
    }
    System.out.println("# Luminosity function:");
    System.out.println("# Mag.\tN\tsigN");

    double magBinWidth = 0.5;

    // Get the range of the data
    double mMin = Double.MAX_VALUE;
    double mMax = -Double.MAX_VALUE;
    for (Source source : sources) {
        double mag = source.getMag(magFilter) - mu;
        mMin = Math.min(mMin, mag);
        mMax = Math.max(mMax, mag);
    }

    // Quantize this to a whole number
    mMin = Math.floor(mMin);
    mMax = Math.ceil(mMax);

    int nBins = (int) Math.rint((mMax - mMin) / magBinWidth);

    // Array to accumulate all objects in each bin
    int[] n = new int[nBins];

    for (Source source : sources) {
        double mag = source.getMag(magFilter) - mu;
        // Bin number
        int bin = (int) Math.floor((mag - mMin) / magBinWidth);
        n[bin]++;
    }

    YIntervalSeries luminosityFunction = new YIntervalSeries("Luminosity Function");

    for (int i = 0; i < nBins; i++) {
        // Bin centre
        double x = mMin + i * magBinWidth + 0.5 * magBinWidth;
        double y = n[i];
        double yErr = n[i] > 0 ? Math.sqrt(y) : 0;
        luminosityFunction.add(x, y, y - yErr, y + yErr);
        System.out.println(x + "\t" + y + "\t" + yErr);
    }

    final YIntervalSeriesCollection data = new YIntervalSeriesCollection();
    data.addSeries(luminosityFunction);

    XYErrorRenderer renderer = new XYErrorRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new Ellipse2D.Float(-1f, -1f, 2, 2));
    renderer.setSeriesPaint(0, ChartColor.BLACK);

    NumberAxis xAxis = new NumberAxis("Absolute Magnitude (" + magFilter.toString() + ")");
    xAxis.setAutoRange(true);
    xAxis.setAutoRangeIncludesZero(false);

    NumberAxis yAxis = new NumberAxis("N");
    yAxis.setAutoRange(true);
    yAxis.setAutoRangeIncludesZero(true);

    // Configure plot
    XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.white);

    // Configure chart
    JFreeChart chart = new JFreeChart("Luminosity Function", xyplot);
    chart.setBackgroundPaint(Color.white);
    chart.setTitle("47 Tuc luminosity function");
    chart.removeLegend();

    final ChartPanel lfChartPanel = new ChartPanel(chart);

    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            JFrame tester = new JFrame();
            tester.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            tester.setLayout(new BorderLayout());
            tester.add(lfChartPanel, BorderLayout.CENTER);
            tester.pack();
            tester.setVisible(true);
        }
    });

}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHistogram.java

@Override
public void resetAxes(final IScope scope) {
    final CategoryPlot pp = (CategoryPlot) this.chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) ((CategoryPlot) this.chart.getPlot()).getRangeAxis();
    if (getY_LogScale(scope)) {
        final LogarithmicAxis logAxis = new LogarithmicAxis(rangeAxis.getLabel());
        logAxis.setAllowNegativesFlag(true);
        ((CategoryPlot) this.chart.getPlot()).setRangeAxis(logAxis);
        rangeAxis = logAxis;//from   ww  w  . j a va 2  s.c  o  m
    }

    if (!useyrangeinterval && !useyrangeminmax) {
        rangeAxis.setAutoRange(true);
    }

    if (this.useyrangeinterval) {
        rangeAxis.setFixedAutoRange(yrangeinterval);
        rangeAxis.setAutoRangeMinimumSize(yrangeinterval);
        rangeAxis.setAutoRange(true);

    }
    if (this.useyrangeminmax) {
        rangeAxis.setRange(yrangemin, yrangemax);

    }

    resetDomainAxis(scope);

    final CategoryAxis domainAxis = ((CategoryPlot) this.chart.getPlot()).getDomainAxis();

    pp.setDomainGridlinePaint(axesColor);
    pp.setRangeGridlinePaint(axesColor);
    pp.setRangeCrosshairVisible(true);

    pp.getRangeAxis().setAxisLinePaint(axesColor);
    pp.getRangeAxis().setLabelFont(getLabelFont());
    pp.getRangeAxis().setTickLabelFont(getTickFont());
    if (textColor != null) {
        pp.getRangeAxis().setLabelPaint(textColor);
        pp.getRangeAxis().setTickLabelPaint(textColor);
    }
    if (getYTickUnit(scope) > 0) {
        ((NumberAxis) pp.getRangeAxis()).setTickUnit(new NumberTickUnit(getYTickUnit(scope)));
    }

    if (getYLabel(scope) != null && !getYLabel(scope).isEmpty()) {
        pp.getRangeAxis().setLabel(getYLabel(scope));
    }
    if (this.series_label_position.equals("yaxis")) {
        pp.getRangeAxis().setLabel(this.getChartdataset().getDataSeriesIds(scope).iterator().next());
        chart.getLegend().setVisible(false);
    }

    if (getXLabel(scope) != null && !getXLabel(scope).isEmpty()) {
        pp.getDomainAxis().setLabel(getXLabel(scope));
    }

    if (this.useSubAxis) {
        for (final String serieid : chartdataset.getDataSeriesIds(scope)) {
            ((SubCategoryAxis) domainAxis).addSubCategory(serieid);
        }

    }
    if (!this.getYTickLineVisible(scope)) {
        pp.setDomainGridlinesVisible(false);
    }

    if (!this.getYTickLineVisible(scope)) {
        pp.setRangeCrosshairVisible(false);

    }

    if (!this.getYTickValueVisible(scope)) {
        pp.getRangeAxis().setTickMarksVisible(false);
        pp.getRangeAxis().setTickLabelsVisible(false);

    }

}

From source file:edu.fullerton.timeseriesapp.TimeSeriesApp.java

public ArrayList<Integer> makePlot(ArrayList<ChanDataBuffer> dbufs, boolean compact) throws WebUtilException {
    int imageId;/*from   w  ww  .ja va  2s. c  om*/
    try {
        PluginSupport psupport = new PluginSupport();
        String gtitle = psupport.getTitle(dbufs, compact);
        String xAxisLabel = "";
        XYSeriesCollection xyds = new XYSeriesCollection();
        TimeSeriesCollection mtds = new TimeSeriesCollection();

        compact = dbufs.size() > 2 ? false : compact;
        for (ChanDataBuffer dbuf : dbufs) {
            int npts = dbuf.getDataLength();
            int sum = 1;
            if (npts > 2000) {
                sum = npts / 2000;
            }
            String legend = psupport.getLegend(dbuf, compact);
            if (timeAxis.equalsIgnoreCase("utc")) {
                TimeSeries ts = psupport.getTimeSeries(dbuf, legend, sum);
                xAxisLabel = "Time (UTC)";
                mtds.addSeries(ts);
            } else {
                boolean isDt = timeAxis.equalsIgnoreCase("dt");
                XYSeries xys = psupport.addXySeries(dbuf, legend, isDt, sum);
                xAxisLabel = psupport.getxAxisLabel();
                xyds.addSeries(xys);
            }
        }
        Double minx, miny, maxx, maxy;
        Double[] rng = new Double[4];

        if (timeAxis.equalsIgnoreCase("utc")) {
            PluginSupport.getRangeLimits(mtds, rng);
        } else {
            int skip = 0;
            PluginSupport.getRangeLimits(xyds, rng, skip);
        }
        minx = rng[0];
        miny = rng[1];
        maxx = rng[2];
        maxy = rng[3];

        int exp;
        if (timeAxis.equalsIgnoreCase("utc")) {
            exp = PluginSupport.scaleRange(mtds, miny, maxy);
        } else {
            exp = PluginSupport.scaleRange(xyds, miny, maxy);
        }

        ChartPanel cpnl;
        DefaultXYDataset ds = new DefaultXYDataset();
        JFreeChart chart;
        if (timeAxis.equalsIgnoreCase("utc")) {
            chart = ChartFactory.createTimeSeriesChart(gtitle, "Time (UTC)", "Counts", ds, true, true, false);
        } else {
            chart = ChartFactory.createXYLineChart(gtitle, xAxisLabel, "Counts", ds, PlotOrientation.VERTICAL,
                    true, false, false);
        }
        chart.setBackgroundPaint(Color.WHITE);
        chart.setAntiAlias(true);

        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

        NumberAxis rangeAxis = new NumberAxis("Counts");
        ScaledAxisNumberFormat sanf = new ScaledAxisNumberFormat();
        sanf.setExp(exp);
        NumberTickUnit tickUnit;
        double plotRange;
        if (maxy != 0 && Math.abs(maxy - miny) < Math.abs(maxy) * 1e-30) {
            // this garbage is to get jFreeChart to always put labels on the Y axis
            double dt = Math.abs(miny) / 10;
            double scaledMin = (miny - dt) * Math.pow(10., exp);
            double scaledMax = (maxy + dt) * Math.pow(10., exp);
            rangeAxis.setRange(scaledMin, scaledMax);
            plotRange = scaledMax - scaledMin;
            rangeAxis.setAutoRange(false);
        } else {
            sanf.setMinMax(miny, maxy);
            plotRange = maxy - miny;
            rangeAxis.setAutoRange(true);
        }
        tickUnit = rangeAxis.getTickUnit();
        double tickSize = tickUnit.getSize();
        int nticks = (int) ((plotRange) / tickSize);
        if (nticks > yTicks) {
            double newTickSize = plotRange / yTicks;
            rangeAxis.setTickUnit(new NumberTickUnit(newTickSize));
        }
        rangeAxis.setNumberFormatOverride(sanf);
        rangeAxis.setAutoRangeIncludesZero(false);
        plot.setRangeAxis(rangeAxis);

        if (timeAxis.equalsIgnoreCase("utc")) {
            plot.setDataset(0, mtds);

        } else {
            plot.setDataset(0, xyds);
        }

        // Set the line thickness
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
        BasicStroke str = new BasicStroke(lineThickness);
        int n = plot.getSeriesCount();
        for (int i = 0; i < n; i++) {
            r.setSeriesStroke(i, str);
        }

        if (compact) {
            chart.removeLegend();
        }
        cpnl = new ChartPanel(chart);
        if (outFilename.isEmpty()) {
            imageId = psupport.saveImageAsPNG(cpnl);
        } else {
            imageId = 0;
            psupport.saveImageAsPdfFile(chart, outFilename);
        }

    } catch (SQLException | NoSuchAlgorithmException | IOException ex) {
        throw new WebUtilException(ex);
    }
    ArrayList<Integer> ret = new ArrayList<>();
    ret.add(imageId);
    return ret;
}

From source file:com.chart.SwingChart.java

/**
 * Set lower and upper limits for an ordinate
 * @param i Axis index/*from   ww w .  j  av  a2s  .com*/
 * @param lower Lower limit
 * @param upper Upper limit
 * @param tick Tick unit
 */
public void setOrdinateRange(int i, double lower, double upper, double tick) {
    NumberAxis e = AxesList.get(i);
    e.setAutoRange(false);
    e.setLowerBound(lower);
    e.setUpperBound(upper);
    e.setTickUnit(new NumberTickUnit(tick));

}

From source file:com.chart.SwingChart.java

/**
 * Set lower and upper limits for an ordinate
 * @param axis Axis to configure//from   ww  w .  ja v a  2  s .  c o m
 */
void setOrdinateRange(final NumberAxis axis) {
    axis.setAutoRange(false);
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(0, 10, 0, 10));
    final TextField tfMax;
    final TextField tfMin;
    final TextField tfTick;
    final TextField tfFuente;
    grid.add(new Label("Axis"), 0, 0);
    grid.add(new Label(axis.getLabel()), 1, 0);
    grid.add(new Label("Lower"), 0, 1);
    grid.add(tfMin = new TextField(), 1, 1);
    grid.add(new Label("Upper"), 0, 2);
    grid.add(tfMax = new TextField(), 1, 2);
    grid.add(new Label("Space"), 0, 3);
    grid.add(tfTick = new TextField(), 1, 3);

    tfMin.setText(String.valueOf(axis.getLowerBound()));
    tfMax.setText(String.valueOf(axis.getUpperBound()));
    tfTick.setText(String.valueOf(axis.getTickUnit().getSize()));

    new PseudoModalDialog(skeleton, grid, true) {
        @Override
        public boolean validation() {
            axis.setLowerBound(Double.valueOf(tfMin.getText()));
            axis.setUpperBound(Double.valueOf(tfMax.getText()));
            axis.setTickUnit(new NumberTickUnit(Double.valueOf(tfTick.getText())));
            return true;
        }
    }.show();

}