TeeChart for android Area issues
Posted: Tue Jan 22, 2013 4:26 pm
Hi, I’m using Tee Chart for Android and I’ve got some troubles using Area Chart.
The first is that the Area chart is only painting the area between the two last points on the chart.
The Second is that the chart does not start in the left side of the layout, there is a weird unused white space before the chart starts. My guess is that the left axis lifts that space but I don’t know how to delete it.
Heare is the code:
I'm using TeeChart Java v1 for Android
I really apreciate your help.
The first is that the Area chart is only painting the area between the two last points on the chart.
The Second is that the chart does not start in the left side of the layout, there is a weird unused white space before the chart starts. My guess is that the left axis lifts that space but I don’t know how to delete it.
Heare is the code:
Code: Select all
import java.util.ArrayList;
import java.util.List;
import com.steema.teechart.BevelStyle;
import com.steema.teechart.TChart;
import com.steema.teechart.axis.Axes;
import com.steema.teechart.axis.Axis;
import com.steema.teechart.drawing.Color;
import com.steema.teechart.drawing.Point;
import com.steema.teechart.drawing.StringAlignment;
import com.steema.teechart.events.ChartMouseEvent;
import com.steema.teechart.events.ChartMouseListener;
import com.steema.teechart.styles.Area;
import com.steema.teechart.styles.Line;
import com.steema.teechart.styles.PointerStyle;
import com.steema.teechart.styles.Series;
import com.steema.teechart.styles.SeriesMarks;
import com.steema.teechart.styles.SeriesXYPoint;
import com.steema.teechart.styles.Shape;
import com.steema.teechart.styles.VerticalAxis;
import com.steema.teechart.tools.Annotation;
import com.steema.teechart.tools.MarksTip;
import com.steema.teechart.tools.AnnotationPosition;
import android.app.Activity;
import android.content.Context;
import android.graphics.Paint.Align;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.view.Display;
public class GraficaLineas{
Context con = null;
List<double []> arraycosas_mes_X = null;
List<double []> arraycosas_mes_Y = null;
private TChart chart;
String mes;
int x11;
int call;
Annotation annotation1;
boolean bandera;
int bsum = 0;
Area series;
TextView numero;
public GraficaLineas(List<double[]> lista_puntitos_x, List<double[]> lista_puntitos_y, Context c, String mes, int call) {
arraycosas_mes_X = lista_puntitos_x;
arraycosas_mes_Y = lista_puntitos_y;
con = c;
this.mes = mes;
this.call = call;
}
public TChart getGrafica(){
chart = new TChart(con);
chart.removeAllSeries();
chart.getAspect().setView3D(false);
chart.removeAllSeries();
chart.getLegend().setVisible(false);
chart.setBackground(Color.WHITE);
chart.getHeader().setVisible(false);
chart.getPanel().setBevelOuter(BevelStyle.NONE);
try{
series = new Area(chart.getChart());
AgregarPuntos();
((Area)chart.getSeries(0)).setColor(Color.fromArgb(197, 208, 220));
series.getAreaBrush().setVisible(true);
((Area)chart.getSeries(0)).getLinePen().setWidth(5);
((Area)chart.getSeries(0)).getLinePen().setColor(Color.fromArgb(196, 207, 219));
chart.getWalls().setVisible(false);
chart.getAxes().getBottom().setAutomatic(false);
chart.getAxes().getBottom().setMaximum(32);
chart.getAxes().getBottom().setMinimum(0.5);
chart.getAxes().getBottom().setVisible(false);
axesStyle(series.getMaxYValue(), series.getMinYValue());
series.getPointer().setColor(Color.fromArgb(169, 188, 206));
series.getPointer().getPen().setColor(Color.fromArgb(169, 188, 206));
series.getPointer().setStyle(PointerStyle.CIRCLE);
series.getPointer().setHorizSize(8);
series.getPointer().setVertSize(8);
series.getPointer().setVisible(true);
series.getAreaLines().setVisible(false);
chart.getAxes().getRight().setVisible(true);
chart.addSeries(series);
annotation1 = new Annotation(chart.getChart());
annotation1.setActive(false);
chart.addChartMouseListener(new ChartMouseListener() {
public void backgroundClicked(ChartMouseEvent arg0) {
bandera = false;
bsum = 0;
Point punto = arg0.getPoint();
double xx = 0;
double yy = 0;
int xxt = 0;
int yyt = 0;
x11 = -1;
xx = 0;
yy = 0;
xxt = 0;
yyt = 0;
x11 = series.getPointer().getSeries().clicked(punto.getX(), punto.getY());
if (x11 != -1){
SeriesXYPoint pts = new SeriesXYPoint(series, x11);
xx = pts.getX();
yy = pts.getY();
}
inicia(x11, xx, yy, punto);
contador();
}
@Override
public void axesClicked(ChartMouseEvent arg0) { }
@Override
public void legendClicked(ChartMouseEvent arg0) { }
@Override
public void titleClicked(ChartMouseEvent arg0) {}
});
return chart;
}catch(Exception e){
Log.e("Excepcion", e + "");
return null;
}
}
void axesStyle(double tamañom, double tamañm){
if (call == 1 || call == 3){
chart.getAxes().getLeft().setAutomatic(false);
chart.getAxes().getLeft().setStartPosition(0);
chart.getAxes().getLeft().setIncrement(1);
chart.getAxes().getLeft().setMaximum(tamañom+1);
chart.getAxes().getLeft().getAxisPen().setVisible(false);
chart.getAxes().getLeft().getGrid().setVisible(false);
chart.getAxes().getLeft().setRelativePosition(100);
}if (call == 2){
chart.getAxes().getLeft().setAutomatic(false);
chart.getAxes().getLeft().setMaximum(tamañom + 500);
if (tamañom > 300){
chart.getAxes().getLeft().setMinimum(tamañm - 300);
}else{ chart.getAxes().getLeft().setMinimum(tamañm);}
chart.getAxes().getLeft().getLabels().setValueFormat("$");
chart.getAxes().getLeft().getAxisPen().setVisible(false);
chart.getAxes().getLeft().getGrid().setVisible(false);
chart.getAxes().getLeft().setRelativePosition(100);
}
}
void inicia (int x11, double xx, double yy, Point punto){
if (x11 != -1){
chart.refreshDrawableState();
annotation1.getShape().setCustomPosition(true);
annotation1.getShape().getPen().setVisible(false);
annotation1.getShape().setColor(Color.fromArgb(240, 240, 240));
annotation1.getShape().getShadow().setColor(Color.fromArgb(172, 221, 243));
Shape forma = new Shape(chart.getChart());
if (call == 1 || call == 3){
annotation1.setText((int) xx + " " + mes + "\n" + (int)yy);
annotation1.getShape().getFont().setColor(Color.fromArgb(98, 163, 222));
annotation1.getShape().getFont().setSize(17);
annotation1.getShape().setLeft(punto.getX());
annotation1.getShape().setTop(punto.getY()-10);
}if (call == 2){
annotation1.setText((int) xx + " " + mes + "\n$" + yy);
annotation1.getShape().getFont().setColor(Color.fromArgb(98, 163, 222));
annotation1.getShape().getFont().setSize(17);
annotation1.getShape().setLeft(punto.getX());
annotation1.getShape().setTop(punto.getY()-10);
}
annotation1.setActive(true);
chart.refreshControl();
x11 = -1;
}
}
Runnable codigoHilo= new Runnable(){
@Override
public void run(){
annotation1.setActive(false);
chart.refreshControl();
}
};
final Handler manejador=new Handler();
protected void contador(){
final Thread t = new Thread(){
public void run(){
bandera = true;
System.out.println(bsum + " , " + bandera);
try{
while(bandera && (bsum < 4000)){
Thread.sleep(1);
bsum = bsum + 1;
}if (bandera){
manejador.post(codigoHilo);
}
} catch (InterruptedException e){
e.printStackTrace();
}
}
};
t.start();
}
private void AgregarPuntos(){
if (call == 2){
for (int i = 0 ; i < (arraycosas_mes_Y.get(0).length - 1); i++){
if (arraycosas_mes_X.get(0)[i] != arraycosas_mes_X.get(0)[i+1]){
series.add(arraycosas_mes_X.get(0)[i], arraycosas_mes_Y.get(0)[i]);
}
}
series.add(arraycosas_mes_X.get(0)[arraycosas_mes_Y.get(0).length - 1], arraycosas_mes_Y.get(0)[arraycosas_mes_Y.get(0).length - 1]);
}if (call == 1 || call == 3){
for (int i = 0 ; i < (arraycosas_mes_Y.get(0).length); i++){
series.add(arraycosas_mes_X.get(0)[i], arraycosas_mes_Y.get(0)[i]);
}
}
}
}
I really apreciate your help.