Page 1 of 1

non-GMT DateTimes offset

Posted: Wed May 21, 2014 9:18 am
by 16969268
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

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

Posted: Wed May 21, 2014 11:11 am
by yeray
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 4254 times

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

Posted: Wed May 21, 2014 11:32 am
by 16969268
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

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

Posted: Wed May 21, 2014 12:22 pm
by yeray
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?

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

Posted: Wed May 21, 2014 1:25 pm
by 16969268
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

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

Posted: Thu May 22, 2014 9:43 am
by 16969268
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

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

Posted: Thu May 22, 2014 9:44 am
by yeray
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