0


I want to rescale a chart but I don't really know to do it. I set to zoom but it is solving my problem.
In fact the data on the plot is displayed in small data.
The code looks like:

public class DrawChart {

private static final Random random = new Random();
RefreshGraph refresh;

public DrawChart(JPanel panel){
    this.refresh = new RefreshGraph();
    this.displayChart (panel);
}

private void displayChart(JPanel jpanel){
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Timer timer = new Timer(1000, new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent e){
            refresh.getRefresh (dataset);
        }
    });
    timer.start ();

    JFreeChart chart = createChart(dataset);

    ChartPanel panel=new ChartPanel(chart);
    panel.setPreferredSize (new Dimension(700,300));
    jpanel.setLayout(new java.awt.BorderLayout());
    jpanel.add (panel, BorderLayout.CENTER);
    jpanel.setVisible(true);
}

private JFreeChart createChart(final CategoryDataset dataset){
    final JFreeChart result = ChartFactory.createLineChart ("", null, null, dataset, PlotOrientation.VERTICAL, true, true, false);

    //Set the background color for the chart
    result.setBackgroundPaint (Color.white);

    //get the plot for customization
    final CategoryPlot plot = result.getCategoryPlot ();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.zoom (0.5);

    CategoryAxis domainAxis = plot.getDomainAxis ();
    final IntervalMarker target = new IntervalMarker(0.25, 1.0);

    //This thread will read the tempory file every minutes and refresh the graph
    Timer timer = new Timer(5000, new ActionListener(){
        public void actionPerformed(ActionEvent e){
            boolean eof_=false;
            try{
                File labelingraph = new File(System.getProperty("user.dir")+"\\period.in");
                if(labelingraph.exists ()){
                    BufferedReader readPeriod = new BufferedReader(new FileReader(labelingraph));
                    while(eof_!=true){
                        String _line = readPeriod.readLine ();
                        if(_line!=null){
                            target.setLabel("Period : "+_line);
                        }else{eof_=true;}
                    }
                }
            }
            catch(IOException io){System.out.println ("Error while accessing the file : "+io.getMessage());}
        }
    });
    timer.start ();

    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);

    return result;
}}

The zoom only zooms out the y-axis values and the line graph itself remains steady.
How can I rescale the graph to make have a good visibility ? Thanks

DeathCoder
  • 145
  • 1
  • 4
  • 19
  • Possible duplicate of [this](http://stackoverflow.com/q/11869704/230513) and [this](http://stackoverflow.com/q/11693929/230513). Please edit your question to include an [sscce](http://sscce.org/) that exhibits the problem you describe. – trashgod Aug 31 '12 at 10:39
  • This [link](http://stackoverflow.com/q/11869704/230513) and this [link](http://stackoverflow.com/q/11693929/230513) have been solved. – DeathCoder Sep 04 '12 at 12:24
  • Excellent; please delete this question or edit it to include an [sscce](http://sscce.org/) that exhibits the problem you describe. – trashgod Sep 04 '12 at 20:02
  • the problem described in this new post is different from others. Here I want to know to re-scale a Linechart. It is displaying very smaller. I have zoomed but it doesnot solve my problem. I want to re-scale the linechart to be viewed properly. I hope I am understandable. Thanks – DeathCoder Sep 05 '12 at 10:14
  • 1
    Without a complete example, I don't know what to suggest. This complete [example](http://stackoverflow.com/a/5522583/230513) zooms OK. – trashgod Sep 05 '12 at 10:23

1 Answers1

0

I solved this by using these lines of codes

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange (1.200, 1.320);
rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits ());
rangeAxis.setTickUnit (new NumberTickUnit(0.005, df, 0));

especially the last line.

Thanks to all

DeathCoder
  • 145
  • 1
  • 4
  • 19