Show Different Dates in X-Axis

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
roop
Newbie
Newbie
Posts: 7
Joined: Wed Aug 06, 2014 12:00 am

Show Different Dates in X-Axis

Post by roop » Wed Apr 01, 2015 5:26 pm

I have a Tchart with FastLine as its chart type. The x-axis is a dateTime and y-axis is some values. I am displaying the X-axis axes as HH:mm. Usually the length of the x-axis is 1 day so the axes is displaying the values correctly starting from 00:00 and ending with 00:00. When the filter is selected for more than one day it is still displaying the axes values correctly, but is there a way how i can even designate the date after every 24hrs for better readability.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Show Different Dates in X-Axis

Post by Yeray » Thu Apr 02, 2015 10:02 am

Hello,

You could draw your texts manually using the chartPainted event.
Here it is an example:

Code: Select all

        tChart1.getPanel().setMarginBottom(15);
        
        tChart1.addChartPaintListener(new ChartPaintAdapter() {

            @Override
            public void chartPainted(ChartDrawEvent e) {
                
                DateTime minDate = new DateTime(tChart1.getAxes().getBottom().getMinimum());
                DateTime maxDate = new DateTime(tChart1.getAxes().getBottom().getMaximum());
                DateTime tmpDate = new DateTime(minDate.getYear(), minDate.getMonth(), minDate.getDay());
                
                int yPosAxis = tChart1.getAxes().getBottom().getPosition();
                
                tChart1.getGraphics3D().getPen().setColor(Color.red);
                tChart1.getGraphics3D().getFont().setColor(Color.red);
                do {
                    if ((tmpDate.after(minDate) || tmpDate.equals(minDate)) &&
                        (tmpDate.before(maxDate) || tmpDate.equals(maxDate))) {
                        int xPosValue = tChart1.getAxes().getBottom().calcPosValue(tmpDate.toDouble());
                        
                        tChart1.getGraphics3D().verticalLine(xPosValue, yPosAxis + 22, yPosAxis + 45);
                        tChart1.getGraphics3D().textOut(xPosValue + 4, yPosAxis + 30, tmpDate.toString("dd MMM"));
                    }
                    tmpDate.add(Calendar.DAY_OF_YEAR, 1);
                } while(tmpDate.before(maxDate));
            }
        });
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply