non-GMT DateTimes offset

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Saman
Newbie
Newbie
Posts: 6
Joined: Fri May 16, 2014 12:00 am

non-GMT DateTimes offset

Post by Saman » Wed May 21, 2014 9:18 am

Hi,

When you use DateTime as chart X axis, the graph is not align properly. It always shifts to right.

Can you please check and let me know how to get this right.

this is the code i used

Code: Select all

@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
		
		LinearLayout group = (LinearLayout) findViewById(R.id.teeChart);
		chart = new TChart(this);
		group.addView(chart);
		
		
		chart.getPanel().setBorderRound(7);
		chart.getAspect().setView3D(false);
		
		
		//common graph settings
		chart.getLegend().setAlignment(LegendAlignment.BOTTOM);
		chart.getLegend().setLegendStyle(LegendStyle.SERIES);
		chart.getLegend().getFont().setSize(20);
		
		chart.getHeader().getFont().setSize(25);
		
		chart.getAxes().getLeft().getTitle().getFont().setSize(15);
		
		chart.getAxes().getLeft().getLabels().getFont().setSize(15);
		
		chart.getAxes().getBottom().getLabels().getFont().setSize(15);
		
		ThemesList.applyTheme(chart.getChart(), 1);
		
		try 
		{
			series = Series.createNewSeries(chart.getChart(), Line.class, null);

			series.getXValues().setDateTime(true);
			
			series.add(new DateTime(2014, 05, 16), 5);
			series.add(new DateTime(2014, 05, 17), 8);
			series.add(new DateTime(2014, 05, 18), 3);
			series.add(new DateTime(2014, 05, 19), 4);
			series.add(new DateTime(2014, 05, 20), 0);
			
			
			series.getMarks().setArrowLength(0);
			series.getMarks().getFont().setSize(15);
			
			chart.getAxes().getBottom().getLabels().setDateTimeFormat("dd MMM");
			
			chart.getAxes().getBottom().setIncrement(Utils.getDateTimeStep(DateTimeStep.ONEDAY));
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
Thanks
Saman

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

Re: TeeChart Java/Java for Android v3.2014.0519 update

Post by Yeray » Wed May 21, 2014 11:11 am

Hello Saman,

This is how it looks for me. How does it look for you?
2014-05-21_1310.png
2014-05-21_1310.png (40.44 KiB) Viewed 18278 times
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

Saman
Newbie
Newbie
Posts: 6
Joined: Fri May 16, 2014 12:00 am

Re: TeeChart Java/Java for Android v3.2014.0519 update

Post by Saman » Wed May 21, 2014 11:32 am

Hi Yeray,

This is what I get (also please note that I am in UK different time zone)

I have attached the photo

Thanks
Saman
Attachments
device-2014-05-21-122540.png
device-2014-05-21-122540.png (53.57 KiB) Viewed 18249 times

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

Re: TeeChart Java/Java for Android v3.2014.0519 update

Post by Yeray » Wed May 21, 2014 12:22 pm

Hello Saman,

This sounds similar to this:
http://bugs.teechart.net/show_bug.cgi?id=420

Could you please show us how do you set your layout?
If you are sharing the LinearLayout for texts and the chart, can you please try using an independent LinearLayout without margins for the Chart?
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

Saman
Newbie
Newbie
Posts: 6
Joined: Fri May 16, 2014 12:00 am

Re: TeeChart Java/Java for Android v3.2014.0519 update

Post by Saman » Wed May 21, 2014 1:25 pm

Hi Yeray,

Following is the code I use.
I changed the layout to only have chart as follows, but still the issue is there.

Layout activity_main.xml

Code: Select all

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Main" >

    <LinearLayout
        android:id="@+id/teeChart"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
    </LinearLayout>
    
</RelativeLayout>
Activity class Main.java

Code: Select all

public class Main extends Activity {

	private TChart chart;
	private Series series;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
		
		LinearLayout group = (LinearLayout) findViewById(R.id.teeChart);
		chart = new TChart(this);
		group.addView(chart);
		
		
		chart.getPanel().setBorderRound(7);
		chart.getAspect().setView3D(false);
		
		
		//common graph settings
		chart.getLegend().setAlignment(LegendAlignment.BOTTOM);
		chart.getLegend().setLegendStyle(LegendStyle.SERIES);
		chart.getLegend().getFont().setSize(20);
		
		chart.getHeader().getFont().setSize(25);
		
		chart.getAxes().getLeft().getTitle().getFont().setSize(15);
		
		chart.getAxes().getLeft().getLabels().getFont().setSize(15);
		
		chart.getAxes().getBottom().getLabels().getFont().setSize(15);
		
		ThemesList.applyTheme(chart.getChart(), 1);
		
		try 
		{
			series = Series.createNewSeries(chart.getChart(), Line.class, null);

			series.getXValues().setDateTime(true);
			
			series.add(new DateTime(2014, 05, 16), 5);
			series.add(new DateTime(2014, 05, 17), 8);
			series.add(new DateTime(2014, 05, 18), 3);
			series.add(new DateTime(2014, 05, 19), 4);
			series.add(new DateTime(2014, 05, 20), 0);
			
			
			series.getMarks().setArrowLength(0);
			series.getMarks().getFont().setSize(15);
			
			chart.getAxes().getBottom().getLabels().setDateTimeFormat("dd MMM");
			
			chart.getAxes().getBottom().setIncrement(Utils.getDateTimeStep(DateTimeStep.ONEDAY));
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
Hope this will help you to check the issue.

Thanks
Saman

Saman
Newbie
Newbie
Posts: 6
Joined: Fri May 16, 2014 12:00 am

Re: TeeChart Java/Java for Android v3.2014.0519 update

Post by Saman » Thu May 22, 2014 9:43 am

Hi Yeray

I found the isuue. Your DateTime only works for GMT time zone. so from the code we have to change the default time zone to GMT

following code worked.

Code: Select all

DateTime dt = new DateTime(2014, 05, 16); 
dt.setTimeZone(TimeZone.getTimeZone("GMT"));
series.add(dt, 5);
dt = new DateTime(2014, 05, 17); 
dt.setTimeZone(TimeZone.getTimeZone("GMT"));
series.add(dt, 8);
dt = new DateTime(2014, 05, 18); 
dt.setTimeZone(TimeZone.getTimeZone("GMT"));
series.add(dt, 3);
dt = new DateTime(2014, 05, 19); 
dt.setTimeZone(TimeZone.getTimeZone("GMT"));
series.add(dt, 4);
dt = new DateTime(2014, 05, 20); 
dt.setTimeZone(TimeZone.getTimeZone("GMT"));
series.add(dt, 0);
Thanks for your support.

Saman

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

Re: TeeChart Java/Java for Android v3.2014.0519 update

Post by Yeray » Thu May 22, 2014 9:44 am

Hello Saman,

Great! Thanks for sharing the solution you found!
I've split the discussion into a new thread to keep the new release announcement clear
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