Page 1 of 1

Show Different Dates in X-Axis

Posted: Wed Apr 01, 2015 5:26 pm
by 17469962
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.

Re: Show Different Dates in X-Axis

Posted: Thu Apr 02, 2015 10:02 am
by yeray
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));
            }
        });