AutoRange and Zoom

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
hmsj
Posts: 1
Joined: Fri Feb 12, 2016 3:29 pm
antibot: No, of course not.

Re: AutoRange and Zoom

Post by hmsj » Fri Feb 12, 2016 3:33 pm

Thank for sharing this code. How can I set restoreAutoDomainBounds()
with Jfreechart's Chart viewer? I am using Javafx

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: AutoRange and Zoom

Post by david.gilbert » Mon Feb 15, 2016 10:06 pm

hmsj wrote:Thank for sharing this code. How can I set restoreAutoDomainBounds()
with Jfreechart's Chart viewer? I am using Javafx
That feature isn't in the ChartViewer yet, but I'll look at adding it.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

bztom333
Posts: 10
Joined: Sat Aug 20, 2016 12:29 am
antibot: No, of course not.

Re: AutoRange and Zoom

Post by bztom333 » Fri Sep 02, 2016 8:08 am

Here's a complete code to include the override of restoreAutoRangeBounds().

Code: Select all


    public class MyChartPanel extends ChartPanel
    {
        public MyChartPanel(JFreeChart chart)
        {
            super(chart);
        }

        @Override
        public void restoreAutoDomainBounds()
        {
            super.restoreAutoDomainBounds();
            // Set your desired range
            DomainAxis.setRange(100000,270000);

        }
        
     

        @Override
        public void restoreAutoRangeBounds()
        {
            super.restoreAutoRangeBounds();
            // Set your desired range
      

            Date minDate = new Date();
            Date maxDate = new Date();
            String dateFormat = "MM/dd/yyyy HH:mm";   
            //set min and max range date
            Calendar cal = new GregorianCalendar();
            cal.setTime(minDate);
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            minDate = cal.getTime();
            cal.set(Calendar.HOUR_OF_DAY, 9);
             maxDate = cal.getTime();
            
            RangeDateaxis.setRange(minDate, maxDate);
            RangeDateaxis.setDateFormatOverride(new SimpleDateFormat(dateFormat));
            
            
        }
    }

Locked