Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on this <a href="https://stackoverflow.com/a/14158305/230513">example</a>, here's an <a href="http://sscce.org/" rel="nofollow noreferrer">sscce</a> that uses <code>setTickUnit()</code> to adjust the domain axis tick unit dynamically, starting from the value <code>5</code>.</p> <p><img src="https://i.stack.imgur.com/BZLir.png" alt="image"></p> <pre><code>import java.awt.BorderLayout; import java.awt.EventQueue; import java.util.Random; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** @see https://stackoverflow.com/a/14167983/230513 */ public class SSCCE { private static final int COUNT = 100; private static final int UNITS = 5; private static final Random r = new Random(); public static void main(String[] args) { XYSeries series = new XYSeries("Data"); for (int i = 0; i &lt; COUNT; i++) { series.add(i, r.nextGaussian()); } XYSeriesCollection data = new XYSeriesCollection(series); final JFreeChart chart = ChartFactory.createXYLineChart("TickUnits", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); final NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setTickUnit(new NumberTickUnit(UNITS)); EventQueue.invokeLater(new Runnable() { @Override public void run() { JFrame f = new JFrame("TickUnitDemo"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new ChartPanel(chart)); final JSpinner spinner = new JSpinner( new SpinnerNumberModel(UNITS, 1, COUNT, 1)); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner s = (JSpinner) e.getSource(); Number n = (Number) s.getValue(); xAxis.setTickUnit(new NumberTickUnit(n.intValue())); } }); JPanel p = new JPanel(); p.add(new JLabel(chart.getTitle().getText())); p.add(spinner); f.add(p, BorderLayout.SOUTH); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload