org.jfree.chart.axis.NumberTickUnit Java Examples

The following examples show how to use org.jfree.chart.axis.NumberTickUnit. 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: JamelAxis.java    From jamel with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void selectAutoTickUnit(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

	final double e = this.getRange().getLength();
	final double ea = Math.pow(10, Math.floor(Math.log10(e / 3)));
	double ep = ea;
	if (ea * 10 < e) {
		ep = ea * 5;
	} else if (ea * 5 < e) {
		ep = ea * 2;
	}
	if (this.integerUnit && ep < 1) {
		ep = 1;
	}
	final NumberTickUnit unit2 = new NumberTickUnit(ep);
	setTickUnit(unit2, false, false);

}
 
Example #2
Source File: HistogramChart.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
synchronized public void addDataset(HistogramPlotDataset newSet, HistogramDataType dataType) {
  dataSet = newSet;
  setAxisNumberFormat(dataType);

  double lower = dataSet.getMinimum();
  double upper = dataSet.getMaximum();

  HistogramDomainAxis axis = (HistogramDomainAxis) plot.getDomainAxis();
  axis.setAutoRange(true);
  axis.setAutoRangeIncludesZero(false);
  axis.setLabel(dataType.toString());
  axis.setRange(lower, upper);
  axis.setLowerTickValue(lower);
  axis.setUpperTickValue(upper);
  axis.setVisibleTickCount(dataSet.getNumberOfBins() + 1);
  axis.setAutoTickUnitSelection(false);
  axis.setTickUnit(new NumberTickUnit(dataSet.getBinWidth()));

  if (dataSet.getItemCount(0) > 6)
    axis.setVerticalTickLabels(true);

  plot.getRangeAxis().setLabel("Number of peaks");
  plot.setDataset(0, newSet);
  setTitle(dataSet.getPeakList().getName(), "Histogram of peaks's " + dataType);
}
 
Example #3
Source File: TaChart.java    From TAcharting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a plot with the given indicators plotted
 * @param chartIndicator org.sjwimmer.tacharting.chart indicators for the plot
 * @return a XYPlot with the indicators as plots
 */
private XYPlot createSubplotFor(ChartIndicator chartIndicator){

    NumberAxis numberAxis = new NumberAxis();

    numberAxis.setLabelFont(new Font("NumberAxisLabelFont",Font.BOLD,8));
    numberAxis.setTickLabelPaint(Color.GRAY);
    numberAxis.setLabelPaint(Color.GRAY);
    numberAxis.setTickUnit(new NumberTickUnit(0.5));
    numberAxis.setTickLabelFont(new Font("NumberAxisBarFont",Font.BOLD,8));
    numberAxis.setAutoTickUnitSelection(true);
    XYPlot indicatorPlot = new XYPlot(chartIndicator.getDataSet(), mainPlot.getDomainAxis(), numberAxis, chartIndicator.getRenderer());
    indicatorPlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    return indicatorPlot;
}
 
Example #4
Source File: HistogramChart.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
synchronized public void addDataset(HistogramPlotDataset newSet, HistogramDataType dataType) {
  dataSet = newSet;
  setAxisNumberFormat(dataType);

  double lower = dataSet.getMinimum();
  double upper = dataSet.getMaximum();

  HistogramDomainAxis axis = (HistogramDomainAxis) plot.getDomainAxis();
  axis.setAutoRange(true);
  axis.setAutoRangeIncludesZero(false);
  axis.setLabel(dataType.toString());
  axis.setRange(lower, upper);
  axis.setLowerTickValue(lower);
  axis.setUpperTickValue(upper);
  axis.setVisibleTickCount(dataSet.getNumberOfBins() + 1);
  axis.setAutoTickUnitSelection(false);
  axis.setTickUnit(new NumberTickUnit(dataSet.getBinWidth()));

  if (dataSet.getItemCount(0) > 6)
    axis.setVerticalTickLabels(true);

  plot.getRangeAxis().setLabel("Number of peaks");
  plot.setDataset(0, newSet);
  setTitle(dataSet.getPeakList().getName(), "Histogram of peaks's " + dataType);
}
 
Example #5
Source File: DelayLineChart.java    From EdgeSim with MIT License 6 votes vote down vote up
@Override
public void draw() {
	XYSeriesCollection collection = new XYSeriesCollection();
	HashMap<String,LinkedList<Data>> dataMap = Controller.getInstance().getResultDataList();
	Iterator<String> it = Controller.getInstance().getResultDataList().keySet().iterator();
	while(it.hasNext()){
		String key = it.next();
		XYSeries series = new XYSeries(key);
		List<Data> dataList = dataMap.get(key);
		series.add(0,0);
		for (Data data2 : dataList) {
			if(yais_max_value == 0 || yais_max_value < data2.getLatency()){
				yais_max_value = data2.getLatency();
			}	
			series.add(data2.getTimeSlice()+1,data2.getLatency());
		}
		collection.addSeries(series);
	}
	yais_space = (int)(yais_max_value/6);
	generateLineChart("Time Slice","Latency(s)",new NumberTickUnit(xais_space), new NumberTickUnit(yais_space),yais_min_value, yais_max_value, collection);

}
 
Example #6
Source File: DefaultPolarPlotEditor.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
@Override
public void updatePlotProperties(Plot plot) {
    super.updatePlotProperties(plot);
    PolarPlot pp = (PolarPlot) plot;
    pp.setAngleTickUnit(new NumberTickUnit(this.manualTickUnitValue));
    pp.setAngleOffset(this.angleOffsetValue);
}
 
Example #7
Source File: DefaultPolarPlotEditor.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updatePlotProperties(Plot plot) {
    super.updatePlotProperties(plot);
    PolarPlot pp = (PolarPlot) plot;
    pp.setAngleTickUnit(new NumberTickUnit(this.manualTickUnitValue));
    pp.setAngleOffset(this.angleOffsetValue);
}
 
Example #8
Source File: DefaultNumberAxisEditor.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the properties of the specified axis to match the properties
 * defined on this panel.
 *
 * @param axis  the axis.
 */
@Override
public void setAxisProperties(Axis axis) {
    super.setAxisProperties(axis);
    NumberAxis numberAxis = (NumberAxis) axis;
    if (!isAutoTickUnitSelection()) {
        numberAxis.setTickUnit(new NumberTickUnit(manualTickUnitValue));
    }
}
 
Example #9
Source File: DefaultLogAxisEditor.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the properties of the specified axis to match the properties
 * defined on this panel.
 *
 * @param axis  the axis.
 */
@Override
public void setAxisProperties(Axis axis) {
    super.setAxisProperties(axis);
    LogAxis logAxis = (LogAxis) axis;
    if (!isAutoTickUnitSelection()) {
        logAxis.setTickUnit(new NumberTickUnit(manualTickUnitValue));
    }
}
 
Example #10
Source File: AbstractAxisCustomizer.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void configNumberAxis(
	NumberAxis numberAxis,
	String tickUnitProp
	) 
{
	if (numberAxis != null)
	{
		Double tickUnit = getDoubleProperty(tickUnitProp);
		if (tickUnit != null)
		{
			numberAxis.setTickUnit(new NumberTickUnit(tickUnit));
		}
	}
}
 
Example #11
Source File: DefaultPolarPlotEditor.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updatePlotProperties(Plot plot) {
    super.updatePlotProperties(plot);
    PolarPlot pp = (PolarPlot) plot;
    pp.setAngleTickUnit(new NumberTickUnit(this.manualTickUnitValue));
    pp.setAngleOffset(this.angleOffsetValue);
}
 
Example #12
Source File: PlotUtil.java    From StockPrediction with MIT License 5 votes vote down vote up
public static void plot(double[] predicts, double[] actuals, String name) {
	double[] index = new double[predicts.length];
	for (int i = 0; i < predicts.length; i++)
		index[i] = i;
	int min = minValue(predicts, actuals);
	int max = maxValue(predicts, actuals);
	final XYSeriesCollection dataSet = new XYSeriesCollection();
	addSeries(dataSet, index, predicts, "Predicts");
	addSeries(dataSet, index, actuals, "Actuals");
	final JFreeChart chart = ChartFactory.createXYLineChart(
			"Prediction Result", // chart title
			"Index", // x axis label
			name, // y axis label
			dataSet, // data
			PlotOrientation.VERTICAL,
			true, // include legend
			true, // tooltips
			false // urls
	);
	XYPlot xyPlot = chart.getXYPlot();
	// X-axis
	final NumberAxis domainAxis = (NumberAxis) xyPlot.getDomainAxis();
	domainAxis.setRange((int) index[0], (int) (index[index.length - 1] + 2));
	domainAxis.setTickUnit(new NumberTickUnit(20));
	domainAxis.setVerticalTickLabels(true);
	// Y-axis
	final NumberAxis rangeAxis = (NumberAxis) xyPlot.getRangeAxis();
	rangeAxis.setRange(min, max);
	rangeAxis.setTickUnit(new NumberTickUnit(50));
	final ChartPanel panel = new ChartPanel(chart);
	final JFrame f = new JFrame();
	f.add(panel);
	f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	f.pack();
	f.setVisible(true);
}
 
Example #13
Source File: DefaultLogAxisEditor.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the properties of the specified axis to match the properties
 * defined on this panel.
 *
 * @param axis  the axis.
 */
@Override
public void setAxisProperties(Axis axis) {
    super.setAxisProperties(axis);
    LogAxis logAxis = (LogAxis) axis;
    if (!isAutoTickUnitSelection()) {
        logAxis.setTickUnit(new NumberTickUnit(manualTickUnitValue));
    }
}
 
Example #14
Source File: DefaultNumberAxisEditor.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the properties of the specified axis to match the properties
 * defined on this panel.
 *
 * @param axis  the axis.
 */
@Override
public void setAxisProperties(Axis axis) {
    super.setAxisProperties(axis);
    NumberAxis numberAxis = (NumberAxis) axis;
    if (!isAutoTickUnitSelection()) {
        numberAxis.setTickUnit(new NumberTickUnit(manualTickUnitValue));
    }
}
 
Example #15
Source File: SpectraVisualizerWindow.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void setAxesRange(double xMin, double xMax, double xTickSize, double yMin, double yMax,
    double yTickSize) {
  NumberAxis xAxis = (NumberAxis) spectrumPlot.getXYPlot().getDomainAxis();
  NumberAxis yAxis = (NumberAxis) spectrumPlot.getXYPlot().getRangeAxis();
  xAxis.setRange(xMin, xMax);
  xAxis.setTickUnit(new NumberTickUnit(xTickSize));
  yAxis.setRange(yMin, yMax);
  yAxis.setTickUnit(new NumberTickUnit(yTickSize));
}
 
Example #16
Source File: TICVisualizerWindow.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public void setAxesRange(double xMin, double xMax, double xTickSize, double yMin, double yMax,
    double yTickSize) {
  NumberAxis xAxis = (NumberAxis) ticPlot.getXYPlot().getDomainAxis();
  NumberAxis yAxis = (NumberAxis) ticPlot.getXYPlot().getRangeAxis();
  xAxis.setRange(xMin, xMax);
  xAxis.setTickUnit(new NumberTickUnit(xTickSize));
  yAxis.setRange(yMin, yMax);
  yAxis.setTickUnit(new NumberTickUnit(yTickSize));
}
 
Example #17
Source File: DefaultPolarPlotEditor.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updatePlotProperties(Plot plot) {
    super.updatePlotProperties(plot);
    PolarPlot pp = (PolarPlot) plot;
    pp.setAngleTickUnit(new NumberTickUnit(this.manualTickUnitValue));
    pp.setAngleOffset(this.angleOffsetValue);
}
 
Example #18
Source File: DefaultNumberAxisEditor.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the properties of the specified axis to match the properties
 * defined on this panel.
 *
 * @param axis  the axis.
 */
@Override
public void setAxisProperties(Axis axis) {
    super.setAxisProperties(axis);
    NumberAxis numberAxis = (NumberAxis) axis;
    if (!isAutoTickUnitSelection()) {
        numberAxis.setTickUnit(new NumberTickUnit(manualTickUnitValue));
    }
}
 
Example #19
Source File: AbstractChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Reduces standard tick unit array to meet  formatting  precision and avoid duplicated values (PRD-5821)
 *
 * @return
 */
protected void standardTickUnitsApplyFormat( NumberAxis numberAxis, NumberFormat format ) {
  final TickUnits standardTickUnits = (TickUnits) numberAxis.getStandardTickUnits();
  TickUnits cutTickUnits = new TickUnits();
  double formatterMinSize = 1 / Math.pow( 10, format.getMaximumFractionDigits() );
  for ( int i = 0; i < standardTickUnits.size(); i++ ) {
    if ( Double.compare( standardTickUnits.get( i ).getSize(), formatterMinSize ) >= 0 ) {
      cutTickUnits.add( new NumberTickUnit( standardTickUnits.get( i ).getSize() ) );
    }
  }
  numberAxis.setStandardTickUnits( cutTickUnits );
}
 
Example #20
Source File: PolarPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new plot.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param radiusAxis  the radius axis (<code>null</code> permitted).
 * @param renderer  the renderer (<code>null</code> permitted).
 */
public PolarPlot(XYDataset dataset, 
                 ValueAxis radiusAxis,
                 PolarItemRenderer renderer) {
  
    super();
        
    this.dataset = dataset;
    if (this.dataset != null) {
        this.dataset.addChangeListener(this);
    }
    this.angleTickUnit = new NumberTickUnit(DEFAULT_ANGLE_TICK_UNIT_SIZE);
    
    this.axis = radiusAxis;
    if (this.axis != null) {
        this.axis.setPlot(this);
        this.axis.addChangeListener(this);
    }
  
    this.renderer = renderer;
    if (this.renderer != null) {
        this.renderer.setPlot(this);
        this.renderer.addChangeListener(this);
    }
  
    this.angleGridlinesVisible = true;
    this.angleGridlineStroke = DEFAULT_GRIDLINE_STROKE;
    this.angleGridlinePaint = DEFAULT_GRIDLINE_PAINT;
  
    this.radiusGridlinesVisible = true;
    this.radiusGridlineStroke = DEFAULT_GRIDLINE_STROKE;
    this.radiusGridlinePaint = DEFAULT_GRIDLINE_PAINT;      
}
 
Example #21
Source File: SpectraVisualizerWindow.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public void setAxesRange(double xMin, double xMax, double xTickSize, double yMin, double yMax,
    double yTickSize) {
  NumberAxis xAxis = (NumberAxis) spectrumPlot.getXYPlot().getDomainAxis();
  NumberAxis yAxis = (NumberAxis) spectrumPlot.getXYPlot().getRangeAxis();
  xAxis.setRange(xMin, xMax);
  xAxis.setTickUnit(new NumberTickUnit(xTickSize));
  yAxis.setRange(yMin, yMax);
  yAxis.setTickUnit(new NumberTickUnit(yTickSize));
}
 
Example #22
Source File: TICVisualizerWindow.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public void setAxesRange(double xMin, double xMax, double xTickSize, double yMin, double yMax,
    double yTickSize) {
  NumberAxis xAxis = (NumberAxis) ticPlot.getXYPlot().getDomainAxis();
  NumberAxis yAxis = (NumberAxis) ticPlot.getXYPlot().getRangeAxis();
  xAxis.setRange(xMin, xMax);
  xAxis.setTickUnit(new NumberTickUnit(xTickSize));
  yAxis.setRange(yMin, yMax);
  yAxis.setTickUnit(new NumberTickUnit(yTickSize));
}
 
Example #23
Source File: NumberTickUnitTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashCode() {
    NumberTickUnit t1 = new NumberTickUnit(1.23, new DecimalFormat("0.00"));
    NumberTickUnit t2 = new NumberTickUnit(1.23, new DecimalFormat("0.00"));
    int h1 = t1.hashCode();
    int h2 = t2.hashCode();
    assertEquals(h1, h2);
}
 
Example #24
Source File: NumberAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    
    NumberAxis a1 = new NumberAxis("Test");
    NumberAxis a2 = new NumberAxis("Test");
    assertTrue(a1.equals(a2));
    
    //private boolean autoRangeIncludesZero;
    a1.setAutoRangeIncludesZero(false);
    assertFalse(a1.equals(a2));
    a2.setAutoRangeIncludesZero(false);
    assertTrue(a1.equals(a2));

    //private boolean autoRangeStickyZero;
    a1.setAutoRangeStickyZero(false);
    assertFalse(a1.equals(a2));
    a2.setAutoRangeStickyZero(false);
    assertTrue(a1.equals(a2));

    //private NumberTickUnit tickUnit;
    a1.setTickUnit(new NumberTickUnit(25.0));
    assertFalse(a1.equals(a2));
    a2.setTickUnit(new NumberTickUnit(25.0));
    assertTrue(a1.equals(a2));

    //private NumberFormat numberFormatOverride;
    a1.setNumberFormatOverride(new DecimalFormat("0.00"));
    assertFalse(a1.equals(a2));
    a2.setNumberFormatOverride(new DecimalFormat("0.00"));
    assertTrue(a1.equals(a2));
    
    a1.setRangeType(RangeType.POSITIVE);
    assertFalse(a1.equals(a2));
    a2.setRangeType(RangeType.POSITIVE);
    assertTrue(a1.equals(a2));
    
}
 
Example #25
Source File: PolarPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new plot.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param radiusAxis  the radius axis (<code>null</code> permitted).
 * @param renderer  the renderer (<code>null</code> permitted).
 */
public PolarPlot(XYDataset dataset,
                 ValueAxis radiusAxis,
                 PolarItemRenderer renderer) {

    super();

    this.dataset = dataset;
    if (this.dataset != null) {
        this.dataset.addChangeListener(this);
    }
    this.angleTickUnit = new NumberTickUnit(DEFAULT_ANGLE_TICK_UNIT_SIZE);

    this.axis = radiusAxis;
    if (this.axis != null) {
        this.axis.setPlot(this);
        this.axis.addChangeListener(this);
    }

    this.renderer = renderer;
    if (this.renderer != null) {
        this.renderer.setPlot(this);
        this.renderer.addChangeListener(this);
    }

    this.angleGridlinesVisible = true;
    this.angleGridlineStroke = DEFAULT_GRIDLINE_STROKE;
    this.angleGridlinePaint = DEFAULT_GRIDLINE_PAINT;

    this.radiusGridlinesVisible = true;
    this.radiusGridlineStroke = DEFAULT_GRIDLINE_STROKE;
    this.radiusGridlinePaint = DEFAULT_GRIDLINE_PAINT;
}
 
Example #26
Source File: NumberTickUnitTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashCode() {
    NumberTickUnit t1 = new NumberTickUnit(1.23, new DecimalFormat("0.00"));
    NumberTickUnit t2 = new NumberTickUnit(1.23, new DecimalFormat("0.00"));
    int h1 = t1.hashCode();
    int h2 = t2.hashCode();
    assertEquals(h1, h2);
}
 
Example #27
Source File: NumberAxisTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {

    NumberAxis a1 = new NumberAxis("Test");
    NumberAxis a2 = new NumberAxis("Test");
    assertTrue(a1.equals(a2));

    //private boolean autoRangeIncludesZero;
    a1.setAutoRangeIncludesZero(false);
    assertFalse(a1.equals(a2));
    a2.setAutoRangeIncludesZero(false);
    assertTrue(a1.equals(a2));

    //private boolean autoRangeStickyZero;
    a1.setAutoRangeStickyZero(false);
    assertFalse(a1.equals(a2));
    a2.setAutoRangeStickyZero(false);
    assertTrue(a1.equals(a2));

    //private NumberTickUnit tickUnit;
    a1.setTickUnit(new NumberTickUnit(25.0));
    assertFalse(a1.equals(a2));
    a2.setTickUnit(new NumberTickUnit(25.0));
    assertTrue(a1.equals(a2));

    //private NumberFormat numberFormatOverride;
    a1.setNumberFormatOverride(new DecimalFormat("0.00"));
    assertFalse(a1.equals(a2));
    a2.setNumberFormatOverride(new DecimalFormat("0.00"));
    assertTrue(a1.equals(a2));

    a1.setRangeType(RangeType.POSITIVE);
    assertFalse(a1.equals(a2));
    a2.setRangeType(RangeType.POSITIVE);
    assertTrue(a1.equals(a2));

}
 
Example #28
Source File: GraphPanel.java    From swift-k with Apache License 2.0 5 votes vote down vote up
private void recalculateUnits() {
    double absmax = Math.max(Math.abs(min), Math.abs(max));
    String prefix = unit.getUnitPrefix(Double.valueOf(absmax));

    this.unitPrefix = prefix;
    this.setLabel(prefix + unit.getName());
    double mult = unit.getMultiplier(absmax);
    double range = max - min;
    double m2 = mult;
    while (range / m2 > 20) {
        m2 = m2 * 10;
    }
 
    this.setTickUnit(new NumberTickUnit(m2, new ShiftingDecimalFormat(mult, "###")));
}
 
Example #29
Source File: DefaultPolarPlotEditor.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updatePlotProperties(Plot plot) {
    super.updatePlotProperties(plot);
    PolarPlot pp = (PolarPlot) plot;
    pp.setAngleTickUnit(new NumberTickUnit(this.manualTickUnitValue));
    pp.setAngleOffset(this.angleOffsetValue);
}
 
Example #30
Source File: DefaultLogAxisEditor.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the properties of the specified axis to match the properties
 * defined on this panel.
 *
 * @param axis  the axis.
 */
@Override
public void setAxisProperties(Axis axis) {
    super.setAxisProperties(axis);
    LogAxis logAxis = (LogAxis) axis;
    if (!isAutoTickUnitSelection()) {
        logAxis.setTickUnit(new NumberTickUnit(manualTickUnitValue));
    }
}