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

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

Introduction

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

Prototype

public NumberAxis(String label) 

Source Link

Document

Constructs a number axis, using default values where necessary.

Usage

From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public void addAxisToPlot(DataItem item) {
    String axisName = item.getName();
    NumberAxis rangeAxis = new NumberAxis(axisName);
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRange(false);/*www.j av  a  2  s.c  o m*/
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    rangeAxis.setNumberFormatOverride(format);
    rangeAxis.setLowerBound(scene.getRangeMin());
    rangeAxis.setUpperBound(scene.getRangeMax());
    plot.setRangeAxis(rangeAxisCount, rangeAxis);
    axisTable.put(item, rangeAxisCount);
    rangeAxisCount++;
}

From source file:net.pickapack.chart.LinePlotFrame.java

/**
 * Create a line plot frame./*w ww.j  a va2s.  c om*/
 *
 * @param linePlot the line plot
 * @param width the width
 * @param height the height
 */
public LinePlotFrame(LinePlot linePlot, int width, int height) {
    super(linePlot.getTitle());
    this.linePlot = linePlot;

    this.numSubPlots = linePlot.getSubLinePlots().size();

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.dataSets = new ArrayList<TimeSeriesCollection>();
    this.dataSinks = new ArrayList<Map<SubLinePlotLine, Function<Double>>>();

    for (SubLinePlot subLinePlot : linePlot.getSubLinePlots()) {
        TimeSeriesCollection dataSetsPerSubPlot = new TimeSeriesCollection();
        this.dataSets.add(dataSetsPerSubPlot);

        HashMap<SubLinePlotLine, Function<Double>> dataSinksPerSubPlot = new HashMap<SubLinePlotLine, Function<Double>>();
        this.dataSinks.add(dataSinksPerSubPlot);

        for (SubLinePlotLine subLinePlotLine : subLinePlot.getLines()) {
            TimeSeries timeSeries = new TimeSeries(subLinePlotLine.getTitle());
            dataSetsPerSubPlot.addSeries(timeSeries);
            dataSinksPerSubPlot.put(subLinePlotLine, subLinePlotLine.getGetValueCallback());
        }

        NumberAxis rangeAxis = new NumberAxis(subLinePlot.getTitleY());
        rangeAxis.setAutoRangeIncludesZero(false);
        XYPlot subplot = new XYPlot(dataSetsPerSubPlot, null, rangeAxis, new StandardXYItemRenderer());
        subplot.setBackgroundPaint(Color.lightGray);
        subplot.setDomainGridlinePaint(Color.white);
        subplot.setRangeGridlinePaint(Color.white);
        plot.add(subplot);
    }

    JFreeChart chart = new JFreeChart(linePlot.getTitle(), plot);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(3600000.0);

    JPanel content = new JPanel(new BorderLayout());

    ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    chartPanel.setPreferredSize(new java.awt.Dimension(width, height));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);

    DataSink dataSink = new DataSink();
    new Thread(dataSink).start();
}

From source file:arduinoserialread.SerialRead.java

private void initGUI() {

    // init the frame
    frame.setTitle("Arduino Serial Read");
    frame.setBounds(100, 100, 600, 500);
    frame.setMinimumSize(new Dimension(600, 500));
    frame.setLocationRelativeTo(null);//from w w w.j  a  v a2s  .co  m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // init control panel
    JPanel ctrlPanel = new JPanel();
    ctrlPanel.setLayout(new FlowLayout());

    // init the serial connection panel
    serialCOM = new SerialConnectionPanel();
    ctrlPanel.add(serialCOM);
    frame.getContentPane().add(ctrlPanel, BorderLayout.SOUTH);

    // init the connection status
    ConnectionStatus connectionStatus = new ConnectionStatus();
    ctrlPanel.add(connectionStatus);

    // init connect and disconnect button
    connect = new JButton("connect");
    ctrlPanel.add(connect);
    disconnect = new JButton("disconnect");
    ctrlPanel.add(disconnect);

    // init real time chart
    TimeSeries series = new TimeSeries("DATA");
    DateAxis timeAxis = new DateAxis("Time");
    dataset = new TimeSeriesCollection(series);
    NumberAxis rangeAxis = new NumberAxis("Data");
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRange(true);
    XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis, new StandardXYItemRenderer());
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.getRenderer().setSeriesPaint(0, new Color(0, 142, 192));
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setAutoRange(true);
    domainAxis.setFixedAutoRange(30000.0); // 30 seconds
    // init the JFreeChart
    JFreeChart chart = new JFreeChart("Real-Time Data Chart", plot);
    chart.setBorderPaint(Color.lightGray);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);
    chart.removeLegend();
    // add real time chart to the frame
    ChartPanel chartPanel = new ChartPanel(chart);
    frame.getContentPane().add(chartPanel, BorderLayout.CENTER);

}

From source file:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param plot//from   ww w  .  j a v a 2 s.  c o  m
 * @return
 */
public static XYPlot getPlot3(XYPlot plot) {
    XYPlot p = new XYPlot(plot.getDataset(), new NumberAxis(plot.getRangeAxis().getLabel()),
            new NumberAxis(plot.getDomainAxis().getLabel()), plot.getRenderer());
    p.setOrientation(PlotOrientation.HORIZONTAL);
    p.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    Logger.getLogger(ChartTools.class.getName()).log(Level.INFO, "fixed auto range: {0}",
            plot.getRangeAxis().getRange().getUpperBound());
    p.getDomainAxis().setFixedAutoRange(500);

    return p;
}

From source file:org.cds06.speleograph.data.Type.java

public NumberAxis getAxis() {
    if (axis == null) {
        axis = new NumberAxis(name + " (" + unit + ")");
    }//from  w  w  w.  j a  v a  2 s  .  c o  m
    return axis;
}

From source file:com.ivli.roim.controls.VOILUTPanel.java

public VOILUTPanel(LUTControl aP) {

    iCurveName = java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("VOILUTPANEL.VOI_LUT");

    iLUT = LUTControl.create(aP);// www  .  ja  v a  2  s .  c o m

    aP.addWindowChangeListener(this);

    initComponents();

    XYPlot plot = new XYPlot();

    plot.setDataset(0, makeLUTCurve());
    plot.setRenderer(0, new XYSplineRenderer());

    ((XYSplineRenderer) plot.getRenderer()).setShapesVisible(false);
    plot.setRangeAxis(0, new NumberAxis(java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle")
            .getString("VOILUTPANEL.AXIS_LABEL_VOI_CURVE")));

    XYSeriesCollection col2 = new XYSeriesCollection();
    col2.addSeries(makeHistogram());

    plot.setDataset(1, col2);
    plot.setRenderer(1, new XYBarRenderer());
    plot.setRangeAxis(1, new NumberAxis(java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle")
            .getString("VOILUTPANEL.AXIS_LABEL_IMAGE_SPACE")));
    plot.mapDatasetToRangeAxis(1, 1);

    plot.setDomainAxis(new NumberAxis(java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle")
            .getString("VOILUTPANEL.AXIS_LABEL_IMAGE_HISTOGRAM")));
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    // change the rendering order so the primary dataset appears "behind" the 
    // other datasets...
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    JFreeChart jfc = new JFreeChart(plot);

    jfc.setBorderVisible(true);
    jfc.removeLegend();
    iPanel = new ChartPanel(jfc);
    iPanel.setSize(jPanel1.getPreferredSize());
    jPanel1.add(iPanel);//, java.awt.BorderLayout.CENTER);              
    iLUT.setSize(jPanel2.getPreferredSize());
    jPanel2.add(iLUT);
    iLabelMin.setText(String.format("%.0f", iLUT.getView().getMin()));
    iLabelMax.setText(String.format("%.0f", iLUT.getView().getMax()));

    validate();
}

From source file:DualAxisDemo2.java

/**
 * A demonstration application showing how to create a time series chart with dual axes.
 *
 * @param title  the frame title./*from w  w w .  jav  a2s  . c o  m*/
 */
public DualAxisDemo2(final String title) {

    super(title);

    // create a title...
    final String chartTitle = "Dual Axis Demo 2";
    final XYDataset dataset = createDataset1();

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset,
            true, true, false);

    //      final StandardLegend legend = (StandardLegend) chart.getLegend();
    //    legend.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    final NumberAxis axis2 = new NumberAxis("Secondary");
    axis2.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, createDataset2());
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer = plot.getRenderer();
    renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        //           rr.setPlotShapes(true);
        rr.setShapesFilled(true);
    }

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

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.esa.smos.gui.gridpoint.GridPointBtDataFlagmatrixTopComponent.java

@Override
protected JComponent createGridPointComponent() {
    dataset = new DefaultXYZDataset();

    final NumberAxis xAxis = new NumberAxis("Record #");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);/*from w w w.j  a v a2 s.  c o  m*/
    xAxis.setUpperMargin(0.0);

    final List<FlagDescriptor> flagDescriptorList = Dddb.getInstance()
            .getFlagDescriptors(DEFAULT_FLAG_DESCRIPTOR_IDENTIFIER).asList();
    flagDescriptors = flagDescriptorList.toArray(new FlagDescriptor[flagDescriptorList.size()]);
    final String[] flagNames = createFlagNames(flagDescriptors);
    final NumberAxis yAxis = createRangeAxis(flagNames);

    final LookupPaintScale paintScale = new LookupPaintScale(0.0, 4.0, Color.WHITE);
    paintScale.add(0.0, Color.BLACK);
    paintScale.add(1.0, Color.RED);
    paintScale.add(2.0, Color.GREEN);
    paintScale.add(3.0, Color.BLUE);
    paintScale.add(4.0, Color.YELLOW);

    renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    renderer.setBaseToolTipGenerator(new FlagToolTipGenerator(flagNames));

    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setForegroundAlpha(0.5f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage("No data");

    chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:playground.artemc.socialCost.MeanTravelTimeWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *///ww w.  j  a  va  2s .co m
private JFreeChart getGraphic(String modeName, double data[]) {

    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries dataSerie = new XYSeries("mean trip travel time", false, true);

    for (int i = 0; i < data.length; i++) {
        dataSerie.add(i, data[i]);
    }

    xyData.addSeries(dataSerie);

    //      final JFreeChart chart = ChartFactory.createXYStepChart(
    final JFreeChart chart = ChartFactory.createXYLineChart("mean travel time, " + modeName, "iteration",
            "travel time", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:org.amanzi.awe.charts.builder.CategoryChartBuilder.java

@Override
protected NumberAxis configRangeAxis(IRangeAxis axis) {
    NumberAxis valueAxis = new NumberAxis(axis.getName());
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return valueAxis;
}