Java Code Examples for org.jfree.chart.axis.NumberAxis#setAutoRangeIncludesZero()

The following examples show how to use org.jfree.chart.axis.NumberAxis#setAutoRangeIncludesZero() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlignmentRansacPlot.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public void printAlignmentChart(String axisTitleX, String axisTitleY) {
  try {
    toolTipGenerator = new AlignmentPreviewTooltipGenerator(axisTitleX, axisTitleY);
    plot.getRenderer().setDefaultToolTipGenerator(toolTipGenerator);
    NumberAxis xAxis = new NumberAxis(axisTitleX);
    xAxis.setNumberFormatOverride(rtFormat);
    xAxis.setAutoRangeIncludesZero(false);
    plot.setDomainAxis(xAxis);

    NumberAxis yAxis = new NumberAxis(axisTitleY);
    yAxis.setNumberFormatOverride(rtFormat);
    yAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(yAxis);

  } catch (Exception e) {
  }
}
 
Example 2
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a filled stepped XY plot with default settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A chart.
 */
public static JFreeChart createXYStepAreaChart(String title, 
        String xAxisLabel, String yAxisLabel, XYDataset dataset,
        boolean legend) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYStepAreaRenderer(
            XYStepAreaRenderer.AREA_AND_SHAPES);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;
}
 
Example 3
Source File: ChartFactory.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a box and whisker chart
 * based on data from a {@link BoxAndWhiskerCategoryDataset}.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  a label for the category axis
 *     (<code>null</code> permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *     permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A box and whisker chart.
 *
 * @since 1.0.4
 */
public static JFreeChart createBoxAndWhiskerChart(String title,
        String categoryAxisLabel, String valueAxisLabel,
        BoxAndWhiskerCategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
            renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;
}
 
Example 4
Source File: ChartFactory.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return The chart.
 */
public static JFreeChart createXYLineChart(String title, String xAxisLabel,
        String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
        boolean legend, boolean tooltips, boolean urls) {

    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example 5
Source File: XYBarRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
public void testFindDomainBounds() {
    XYSeriesCollection dataset 
            = RendererXYPackageTests.createTestXYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYBarChart("Test Chart", "X", 
            false, "Y", dataset, PlotOrientation.VERTICAL, false, false, 
            false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example 6
Source File: StackedXYBarRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example 7
Source File: ChartFactory.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a box and whisker chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A box and whisker chart.
 */
public static JFreeChart createBoxAndWhiskerChart(String title,
        String timeAxisLabel, String valueAxisLabel,
        BoxAndWhiskerXYDataset dataset, boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);
    XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example 8
Source File: DensityPlotPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private void createUI() {
    plot = new XYImagePlot();
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0);
    domainAxis.setLowerMargin(0);
    rangeAxis.setUpperMargin(0);
    rangeAxis.setLowerMargin(0);
    plot.setNoDataMessage(NO_DATA_MESSAGE);
    plot.getRenderer().setBaseToolTipGenerator(new XYPlotToolTipGenerator());
    JFreeChart chart = new JFreeChart(CHART_TITLE, plot);
    ChartFactory.getChartTheme().apply(chart);

    chart.removeLegend();
    createUI(createChartPanel(chart), createOptionsPanel(), bindingContext);
    updateUIState();
}
 
Example 9
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that only one chart change event is generated by a change to a
 * subplot.
 */
public void testNotification() {
    CombinedDomainXYPlot plot = createPlot();
    JFreeChart chart = new JFreeChart(plot);
    chart.addChangeListener(this);
    XYPlot subplot1 = (XYPlot) plot.getSubplots().get(0);
    NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(!yAxis.getAutoRangeIncludesZero());
    assertEquals(1, this.events.size());

    // a redraw should NOT trigger another change event
    BufferedImage image = new BufferedImage(200, 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    this.events.clear();
    chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0));
    assertTrue(this.events.isEmpty());
}
 
Example 10
Source File: ChartFactory.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a box and whisker chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A box and whisker chart.
 */
public static JFreeChart createBoxAndWhiskerChart(String title,
                                             String timeAxisLabel,
                                             String valueAxisLabel,
                                             BoxAndWhiskerXYDataset dataset,
                                             boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);
    XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, 
            legend);

}
 
Example 11
Source File: ChartFactory.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return The chart.
 */
public static JFreeChart createXYLineChart(String title, String xAxisLabel,
        String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
        boolean legend, boolean tooltips, boolean urls) {

    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example 12
Source File: CombinedRangeXYPlotTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a sample plot.
 *
 * @return A sample plot.
 */
private CombinedRangeXYPlot createPlot() {
    // create subplot 1...
    XYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    NumberAxis xAxis1 = new NumberAxis("X1");
    XYPlot subplot1 = new XYPlot(data1, xAxis1, null, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    XYTextAnnotation annotation
            = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    XYDataset data2 = createDataset2();
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    NumberAxis xAxis2 = new NumberAxis("X2");
    xAxis2.setAutoRangeIncludesZero(false);
    XYPlot subplot2 = new XYPlot(data2, xAxis2, null, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis(
            "Range"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}
 
Example 13
Source File: ChartLogics.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Auto range the range axis
 * 
 * @param myChart
 * @param zoom
 * @param autoRangeY if true the range (Y) axis auto bounds will be restored
 */
public static void autoDomainAxis(ChartPanel myChart) {
  XYPlot plot = (XYPlot) myChart.getChart().getPlot();
  NumberAxis axis = (NumberAxis) plot.getDomainAxis();
  // trick. Otherwise auto range will fail sometimes
  axis.setRange(axis.getRange());
  axis.setAutoRangeIncludesZero(false);
  myChart.restoreAutoDomainBounds();
}
 
Example 14
Source File: ChartFactory.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a bubble chart with default settings.  The chart is composed of
 * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis,
 * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer}
 * to draw the data items.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A bubble chart.
 */
public static JFreeChart createBubbleChart(String title, String xAxisLabel,
        String yAxisLabel, XYZDataset dataset, PlotOrientation orientation,
        boolean legend, boolean tooltips, boolean urls) {

    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);

    XYItemRenderer renderer = new XYBubbleRenderer(
            XYBubbleRenderer.SCALE_ON_RANGE_AXIS);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYZURLGenerator());
    }
    plot.setRenderer(renderer);
    plot.setOrientation(orientation);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example 15
Source File: SWTMultipleAxisDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 * 
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 
            200);
    
    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3", 
        "Time of Day", 
        "Primary Range Axis",
        dataset1, 
        true, 
        true, 
        false
    );

    chart.setBackgroundPaint( Color.white );
    chart.setBorderVisible( true );
    chart.setBorderPaint( Color.BLACK );
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");  
    chart.addSubtitle( subtitle );
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);
   
    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setFixedDimension(10.0);
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);
    
    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible( true );
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4        
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);
    
    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);
    
    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);        
    plot.setRenderer(3, renderer4);
            
    return chart;
}
 
Example 16
Source File: Scatterplot.java    From chipster with MIT License 4 votes vote down vote up
@Override
public JComponent getVisualisation(DataBean data) throws Exception {

	this.data = data;

	refreshAxisBoxes(data);

	List<Variable> vars = getFrame().getVariables();
	if (vars == null || vars.size() < 2) {
		if (xBox.getItemCount() >= 1) {
			xBox.setSelectedIndex(0);
		}
		if (yBox.getItemCount() >= 2) {
			yBox.setSelectedIndex(1);
		} else {
			yBox.setSelectedIndex(0);
		}
	} else {
		xBox.setSelectedItem(vars.get(0));
		yBox.setSelectedItem(vars.get(1));
	}

	xVar = (Variable) xBox.getSelectedItem();
	yVar = (Variable) yBox.getSelectedItem();

	PlotDescription description = new PlotDescription(data.getName(), xVar.getName(), yVar.getName());

	NumberAxis domainAxis = new NumberAxis(description.xTitle);
	domainAxis.setAutoRangeIncludesZero(false);
	NumberAxis rangeAxis = new NumberAxis(description.yTitle);
	rangeAxis.setAutoRangeIncludesZero(false);
	
	XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();		
	renderer.setLinesVisible(false);
	renderer.setShapesVisible(true);
	renderer.setShape(new Ellipse2D.Float(-2, -2, 4, 4));
	renderer.setSeriesPaint(1, Color.black);
	
	plot = new XYPlot(new XYSeriesCollection(), domainAxis, rangeAxis, renderer);
	
	this.updateSelectionsFromApplication(false);		//Calls also updateXYSerieses();
	
	JFreeChart chart = new JFreeChart(description.plotTitle, plot);

	application.addClientEventListener(this);

	selectableChartPanel = new SelectableChartPanel(chart, this); 
	return selectableChartPanel;
}
 
Example 17
Source File: SWTMultipleAxisDemo1.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(),
            200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Multiple Axis Demo 3",
        "Time of Day",
        "Primary Range Axis",
        dataset1,
        true,
        true,
        false
    );

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(),
            170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(),
            170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}
 
Example 18
Source File: NumberLineChart.java    From EdgeSim with MIT License 4 votes vote down vote up
public NumberLineChart() {	
		this.collection = this.getCollection();
		initial();
		this.chart = ChartFactory.createXYLineChart(
				null, 
				"Request",
				"Hit Rate", 
				collection, 
				PlotOrientation.VERTICAL, 
				true, 
				true, 
				false
		);
		
		this.chart.getPlot().setBackgroundPaint(SystemColor.white);
		LegendTitle legend = chart.getLegend();
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setHorizontalAlignment(HorizontalAlignment.LEFT);

		

		
		XYPlot plot = (XYPlot) chart.getPlot();		
		
		NumberAxis numberAxisX = (NumberAxis) chart.getXYPlot().getDomainAxis();
		numberAxisX.setTickUnit(new NumberTickUnit(500));
//		numberAxisX.setAutoRangeMinimumSize(0.1);
		numberAxisX.setAutoRangeIncludesZero(true);
		numberAxisX.setAxisLineVisible(false);
		numberAxisX.setTickMarkInsideLength(4f);
		numberAxisX.setTickMarkOutsideLength(0);

		
		
		NumberAxis numberAxisY = (NumberAxis) chart.getXYPlot().getRangeAxis();
		numberAxisY.setTickUnit(new NumberTickUnit(0.2));
		numberAxisY.setRangeWithMargins(0,1);
		numberAxisY.setAutoRangeIncludesZero(true);
		numberAxisY.setAxisLineVisible(false);
		numberAxisY.setTickMarkInsideLength(4f);
		numberAxisY.setTickMarkOutsideLength(0);
		// ����Y������Ϊ�ٷֱ�
		numberAxisY.setNumberFormatOverride(NumberFormat.getPercentInstance());
		
		
		
		XYItemRenderer xyitem = plot.getRenderer();   
        xyitem.setDefaultItemLabelsVisible(true);
//        ItemLabelsVisible(true);

		xyitem.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
//        xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
//        xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 12));
		xyitem.setDefaultItemLabelFont(new Font("Dialog", 1, 12));
        plot.setRenderer(xyitem);
		
		 	XYLineAndShapeRenderer renderer =  (XYLineAndShapeRenderer)plot.getRenderer();
			renderer.setDefaultItemLabelsVisible(true);
			renderer.setDefaultShapesVisible(true);
			renderer.setDrawOutlines(true);
			
			renderer.setSeriesOutlineStroke(0, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(1, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(2, new BasicStroke(5F));
			renderer.setSeriesOutlineStroke(3, new BasicStroke(5F));


			
			renderer.setSeriesPaint(0, Color.RED);
			renderer.setSeriesPaint(1, new Color(53,101,253));
			renderer.setSeriesPaint(2, new Color(0,161,59));//����ɫ
			renderer.setSeriesPaint(3, new Color(148,103,189));//��ɫ
			

			renderer.setSeriesStroke(0, new BasicStroke(4.0F));
			renderer.setSeriesStroke(1, new BasicStroke(4.0F));
			renderer.setSeriesStroke(2, new BasicStroke(4.0F));
			renderer.setSeriesStroke(3, new BasicStroke(4.0F));
			renderer.setSeriesStroke(4, new BasicStroke(2.0F));
			renderer.setSeriesStroke(5, new BasicStroke(2.0F));
		
			this.chartFrame = new ChartFrame("Line Chart", chart);
			chartFrame.pack();
			chartFrame.setSize(1600,1200);
			chartFrame.setLocation(300,200);
			chartFrame.setVisible(true);
	}
 
Example 19
Source File: PseudoSpectrum.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public static JFreeChart createChart(PseudoSpectrumDataSet dataset, RawDataFile raw, boolean sum,
    String title) {
  //
  JFreeChart chart = ChartFactory.createXYLineChart(title, // title
      "m/z", // x-axis label
      "Intensity", // y-axis label
      dataset, // data set
      PlotOrientation.VERTICAL, // orientation
      true, // isotopeFlag, // create legend?
      true, // generate tooltips?
      false // generate URLs?
  );
  chart.setBackgroundPaint(Color.white);
  chart.getTitle().setVisible(false);
  // set the plot properties
  XYPlot plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(RectangleInsets.ZERO_INSETS);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(false);
  plot.setRangeCrosshairVisible(false);

  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
  NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(mzFormat);
  xAxis.setUpperMargin(0.08);
  xAxis.setLowerMargin(0.00);
  xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));
  xAxis.setAutoRangeIncludesZero(true);
  xAxis.setMinorTickCount(5);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(intensityFormat);
  yAxis.setUpperMargin(0.20);

  PseudoSpectraRenderer renderer = new PseudoSpectraRenderer(Color.BLACK, false);
  plot.setRenderer(0, renderer);
  plot.setRenderer(1, renderer);
  plot.setRenderer(2, renderer);
  renderer.setSeriesVisibleInLegend(1, false);
  renderer.setSeriesPaint(2, Color.ORANGE);
  //
  return chart;
}
 
Example 20
Source File: MsMsPlot.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
MsMsPlot(RawDataFile rawDataFile, MsMsVisualizerWindow visualizer, MsMsDataSet dataset,
    Range<Double> rtRange, Range<Double> mzRange) {

  super(ChartFactory.createXYLineChart("", "", "", null, PlotOrientation.VERTICAL, true, true,
      false), true, true, false, false, true);

  this.visualizer = visualizer;
  this.rawDataFile = rawDataFile;
  this.rtRange = rtRange;
  this.mzRange = mzRange;

  // initialize the chart by default time series chart from factory
  chart = getChart();
  chart.setBackgroundPaint(Color.white);

  // disable maximum size (we don't want scaling)
  // setMaximumDrawWidth(Integer.MAX_VALUE);
  // setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
  plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // Set the domain log axis
  xAxis = new NumberAxis("Retention time (min)");
  xAxis.setAutoRangeIncludesZero(false);
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0.01);
  xAxis.setLowerMargin(0.01);
  plot.setDomainAxis(xAxis);

  // Set the range log axis
  yAxis = new NumberAxis("Precursor m/z");
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);
  yAxis.setUpperMargin(0.1);
  yAxis.setLowerMargin(0.1);
  plot.setRangeAxis(yAxis);

  // Set crosshair properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  // Create renderers
  mainRenderer = new MsMsPlotRenderer();
  plot.setRenderer(0, mainRenderer);

  // title
  chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chartSubTitle = new TextTitle();
  chartSubTitle.setFont(subTitleFont);
  chartSubTitle.setMargin(5, 0, 0, 0);
  chart.addSubtitle(chartSubTitle);

  // Add data sets;
  plot.setDataset(0, dataset);

  // set rendering order
  plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

  peakDataRenderer = new PeakDataRenderer();


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}