android edittext can not fetch data - android

In my android program I am using achartengine library for showing a pie chart.
The basic of the program is I have an activity,where I have 2 edit text fields and a button.after fill up the edit text field ,when click the button it will show a popup window with piechart..
here,I am using NAME_LIST as a string type array. where value of edit text will store and after we can fetch..
the code is given below:---
public class AndroidPopupWindowActivity111_new extends Activity {
private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN };
LinearLayout layout;
private CategorySeries mSeries = new CategorySeries("");
private DefaultRenderer mRenderer = new DefaultRenderer();
private GraphicalView mChartView;
EditText name1,name2;
private int[] VALUES = { 40,60 };
String x1,y1;
String[] NAME_LIST ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_main);
name1=(EditText) findViewById(R.id.ext1);
name2=(EditText) findViewById(R.id.ext2);
x1=name1.getText().toString();
y1=name2.getText().toString();
NAME_LIST = new String[] { x1 , y1 };
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.main_piechart, null);
final PopupWindow popupWindow = new PopupWindow( popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layout = (LinearLayout)popupView.findViewById(R.id.chart);
layout.addView(mChartView);
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + "(" + VALUES[i]+"%)", VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
}});
}
}
But the problem is the name is not fetching from edittext..I am giving an example what error is occuring.:--
Click the picture to know the problem...in this picture A,B,C,D is the edit text values..in my output A,B,C,D is showing as "null"
where is the problem??????????thanks in advance

When you're initializing
String[] NAME_LIST = new String[] { x1,y1 };
x1 and y1 are null. Changing the values of x1 and y1 later will not change the values in NAME_LIST.
Add the line
NAME_LIST = new String[] { x1,y1 };
just before the for loop in OnCreate(). It will work.
EDIT:
Move these five lines
name1=(EditText) findViewById(R.id.ext1);
name2=(EditText) findViewById(R.id.ext2);
x1=name1.getText().toString();
y1=name2.getText().toString();
NAME_LIST = new String[] { x1 , y1 };
into the onClick() method, just before the for loop begins.

Related

In android how to performm task one after another

In my program, the basic is:-
When the program open it will show an animation then it will show pie chart result.
my code is:---
public class Popup_animation11 extends Activity {
private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN };
LinearLayout layout;
private CategorySeries mSeries = new CategorySeries("");
private DefaultRenderer mRenderer = new DefaultRenderer();
private GraphicalView mChartView;
Context ctx;
private TransparentProgressDialog pd;
private Handler h;
private Runnable r;
EditText name1,name2;
private int[] VALUES = { 40, 60 };
String x1,y1;
Button btnOpenPopup;
String[] NAME_LIST ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_main);
Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
pd.show();
}
});
h = new Handler();
pd = new TransparentProgressDialog(this, R.drawable.uktrafficlights);
r =new Runnable() {
#Override
public void run() {
if (pd.isShowing()) {
pd.dismiss();
}
}
};
}
#Override
protected void onDestroy() {
h.removeCallbacks(r);
if (pd.isShowing() ) {
pd.dismiss();
}
super.onDestroy();
}
private class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context, int resourceIdOfImage) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
layout.addView(iv, params);
addContentView(layout, params);
}
#Override
public void show() {
super.show();
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
anim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
//here display data
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
mChartView = ChartFactory.getPieChartView(ctx, mSeries, mRenderer);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.main_piechart, null);
final PopupWindow popupWindow = new PopupWindow( popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layout = (LinearLayout)popupView.findViewById(R.id.chart);
layout.addView(mChartView);
name1=(EditText) findViewById(R.id.ext1);
name2=(EditText) findViewById(R.id.ext2);
x1=name1.getText().toString();
y1=name2.getText().toString();
NAME_LIST = new String[] { x1 , y1 };
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + "(" + VALUES[i]+"%)", VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
}
}
}
But the problem is when I open the program, animation is running and running.the result is not coming.
I requirement was first animation then the result..But only animation is running.. Where is the problem in my code? thanks in advance
my edited code is:---
public class Popup_animation11 extends Activity {
private static int[] COLORS = new int[] { Color.MAGENTA, Color.CYAN };
LinearLayout layout;
private CategorySeries mSeries = new CategorySeries("");
private DefaultRenderer mRenderer = new DefaultRenderer();
private GraphicalView mChartView;
Context ctx;
private TransparentProgressDialog pd;
private Handler h;
private Runnable r;
EditText name1,name2;
private int[] VALUES = { 40,60 };
String x1,y1;
Button btnOpenPopup;
String[] NAME_LIST ;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup_main);
Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
pd.show();
}
});
h = new Handler();
pd = new TransparentProgressDialog(this, R.drawable.uktrafficlights);
r =new Runnable() {
#Override
public void run() {
if (pd.isShowing()) {
pd.dismiss();
}
}
};
}
#Override
protected void onDestroy() {
h.removeCallbacks(r);
if (pd.isShowing() ) {
pd.dismiss();
}
super.onDestroy();
}
private class TransparentProgressDialog extends Dialog {
private ImageView iv;
public TransparentProgressDialog(Context context, int resourceIdOfImage) {
super(context, R.style.TransparentProgressDialog);
WindowManager.LayoutParams wlmp = getWindow().getAttributes();
wlmp.gravity = Gravity.CENTER_HORIZONTAL;
getWindow().setAttributes(wlmp);
setTitle(null);
setCancelable(false);
setOnCancelListener(null);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
layout.addView(iv, params);
addContentView(layout, params);
}
#Override
public void show() {
super.show();
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
anim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
//here display data
h.postDelayed(r, 100);
pd.dismiss();
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
mChartView = ChartFactory.getPieChartView(ctx, mSeries, mRenderer);
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.main_piechart, null);
final PopupWindow popupWindow = new PopupWindow( popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
layout = (LinearLayout)popupView.findViewById(R.id.chart);
layout.addView(mChartView);
name1=(EditText) findViewById(R.id.ext1);
name2=(EditText) findViewById(R.id.ext2);
x1=name1.getText().toString();
y1=name2.getText().toString();
NAME_LIST = new String[] { x1 , y1 };
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + "(" + VALUES[i]+"%)", VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
}
}
}
Try call anim.setAnimationListener() before call iv.startAnimation(anim);

How can I recreate piechart (AChartEngine) on spinner item click in Android?

Am using AChartEngine library to displaying data's in PieChart view in my project. Initially I created Dataset, Render, View and Chart Factory to create PieChart and its working fine. For eg PieChart for Gender
OnCreate(){
malecount = 3;
femalecount = 1;
createpiechart(); // Creating PieChart initially
}
This code is working fine. PieChart with male & Female with 2 different colors that mentioned as static.
Now I add Spinner for filters, add event for that Spinner OnItemSelectedListener.
String selectedItem = parent.getItemAtPosition(position).toString();
if(selectedItem.equals("Last Week"))
{
malecount = 2; femalecount = 1; // clear existing values from temp memory and add new values
mSeries.clear(); // clear the dataset
createpiechart(); // recreate piechart
}
in that create piechart method again execute the same code as before.
private void createpiechart() {
VALUES = new int[] { malecount, femalecount };
mRenderer.setChartTitle("Gender");
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsColor(0xff000000); // Black color
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setStartAngle(90);
for (int i = 0; i < VALUES.length; i++) {
mSeries.add(NAME_LIST[i] + " " + VALUES[i], VALUES[i]);
SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
renderer.setColor(COLORS[(mSeries.getItemCount() - 1)
% COLORS.length]);
mRenderer.addSeriesRenderer(renderer);
}
if (mChartView != null) {
mChartView.repaint();
}
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(10);
mChartView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// nothing
}
});
layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
else {
mChartView.repaint();
}
}
After executing the same code Green and Blue color of Male & Female in Bottom changes to white color, I need same color before it shown. Check this image below and help me how to change that color back or whats wrong with this code ?
Just clear Dataset and Renderer and then pass new values.
To clear dataset
int size = dataset.getSeriesCount();
for (int i = 0; i < size; i++) {
dataset.removeSeries(0);
}
To clear Renderer renderer.removeAllRenderers();

Radius of Doughnut chart in AchartEngine

I m trying to set doughnut chart inner circle radius and outter circle radius in aChartengine, below is my code :
public class MainActivity extends Activity {
GraphicalView gv;
RelativeLayout rl;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<double[]> values1 = new ArrayList<double[]>();
values1.add(new double[] { 15, 5 });
gv = createIntent(values1);
rl = (RelativeLayout) findViewById(R.id.rel);
rl.addView(gv);
}
#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;
}
public GraphicalView createIntent(List<double[]> values1) {
List<String[]> titles = new ArrayList<String[]>();
titles.add(new String[] { " ", " " });
int[] colors = new int[] { Color.BLUE, Color.GREEN };
DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setApplyBackgroundColor(true);
renderer.setShowLegend(false);
renderer.setShowLabels(false);
renderer.setStartAngle(270);
renderer.setBackgroundColor(Color.rgb(222, 222, 200));
renderer.setLabelsColor(Color.GRAY);
return ChartFactory.getDoughnutChartView(MainActivity.this,
buildMultipleCategoryDataset("Project budget", titles, values1),
renderer);
}
protected MultipleCategorySeries buildMultipleCategoryDataset(String title,
List<String[]> titles, List<double[]> values) {
MultipleCategorySeries series = new MultipleCategorySeries(title);
int k = 0;
for (double[] value : values) {
series.add(2007 + k + "", titles.get(k), value);
k++;
}
return series;
}
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
DefaultRenderer renderer = new DefaultRenderer();
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setMargins(new int[] { 20, 30, 15, 0 });
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
But I have browser this query of setting radius , in many search I have found radius on canvas but in my case I don't have canvas.
Can anyone tell me how to set radius here in my code ?
renderer.setScale((flaot)1.3) solved my problem but the inner and outer radius is approx not prefect.
You have to just chage value of decCoef (variable in DoughnutChart class).
In DefaultRenderer add your own radius variable and create getter and setter.
now, use this variable in DoughnutChart.
for example ,
DefaultRenderer defaultRenderer = new DefaultRenderer();
defaultRenderer.setmWidth(0.1f);
In DoughnutChart class :
public class DoughnutChart extends RoundChart {
private float mWidth; // make your own variable and initialize in constructor
public DoughnutChart(MultipleCategorySeries dataset, DefaultRenderer renderer) {
super(null, renderer);
mDataset = dataset;
mWidth = renderer.getmWidth();
}
double decCoef = mWidth / cLength; // change value of decCoef by using our variable.

How to draw tow donut Graph with two different color using aChartEngine in Android?

I am using aChartEngine Library to draw donut in my android application.I want to make two donut - one inside another with two different color. But I am unable to make them with two different color.This is my donut class which draw donut in LinearLayout.
public class PunchStatGraph {
private GraphicalView mChartView2;
static int count = 2;
int[] Mycolors = new int[] { Color.parseColor("#D4272D"),
Color.parseColor("#6F1717") };
String[] average = { "SPEED", "FORCE"};
String[] max = { "SPEED", "FORCE"};
public Intent execute(Context context, LinearLayout parent, double avg_values[],double max_values[]) {
parent.removeAllViews();
int[] colors = new int[count];
for (int i = 0; i < count; i++) {
colors[i] = Mycolors[i];
}
DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setShowLabels(false);
renderer.setBackgroundColor(Color.BLACK);
renderer.setPanEnabled(false);// Disable User Interaction
renderer.setScale((float) 1.4);
renderer.setInScroll(true); //To avoid scroll Shrink
renderer.setStartAngle(90);
renderer.setShowLegend(false);
MultipleCategorySeries categorySeries = new MultipleCategorySeries(
"Punch Graph");
categorySeries.add(average, avg_values);
categorySeries.add(max, max_values);
mChartView2 = ChartFactory.getDoughnutChartView(context,
categorySeries, renderer);
parent.addView(mChartView2);
return ChartFactory.getDoughnutChartIntent(context, categorySeries,
renderer, null);
}
protected DefaultRenderer buildCategoryRenderer(int[] colors) {
DefaultRenderer renderer = new DefaultRenderer();
for (int color : colors) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(color);
renderer.addSeriesRenderer(r);
}
return renderer;
}
}
Check Image also.Thanks in advance.

Several questions to AChartEngine

I am new to AchartEngine. I am using AchartEngine with android to create a Barchart. I have looked at the aChartEngine API and have created a Barchart, its working fine.
When I want to see my actual view I have to decrease the zoom rate by clicking zoom button which is in right bottom. I need to show a compleate Barchart what I exactly declared in my program with out using zoom button.
I need to navigate from one view to another. So, I created one graphical view with ontouchlistner, but it shows error.
Any ideas would be greatly appreciated. Am I missing something here?
public class GraphicViewExample extends Activity {
private String[] mMonth = new String[] { "Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
int[] x = { 0, 1, 2, 3, 4, 5, 6, 7 };
int[] income = { 2000, 2500, 2700, 3000, 2800, 3500, 3700, 3800 };
public static final String TYPE = "type";
private XYMultipleSeriesDataset mDataset = getDemoDataset();
private XYMultipleSeriesRenderer mRenderer = getDemoRenderer();
private GraphicalView mChartView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.graphicviewexample);
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getBarChartView(this, mDataset,
mRenderer, Type.DEFAULT);
mRenderer.setSelectableBuffer(100);
layout.addView(mChartView, new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
} else {
mChartView.repaint();
}
mChartView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
#SuppressWarnings("unused")
/*SeriesSelection seriesSelection = mChartView
.getCurrentSeriesAndPoint();*/
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
mRenderer.removeAllRenderers();
r.setColor(Color.RED);
mChartView.repaint();
return true;
}
});
/*mChartView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
* LinearLayout slayout = (LinearLayout)
* findViewById(R.id.chart); ChartView =
* ChartFactory.getBarChartView( getApplicationContext(),
* sDataset, smRenderer, Type.DEFAULT);
* slayout.addView(ChartView, new LayoutParams(
* LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
*
* ChartView.repaint();
mChartView.repaint();
}
});*/
}
private XYMultipleSeriesDataset getDemoDataset() {
XYSeries incomeSeries = new XYSeries("Income");
for (int i = 0; i < x.length; i++) {
incomeSeries.add(i, income[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(incomeSeries);
return dataset;
}
private XYMultipleSeriesRenderer getDemoRenderer() {
XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
incomeRenderer.setColor(Color.rgb(130, 130, 230));
incomeRenderer.setFillPoints(true);
incomeRenderer.setLineWidth(2);
incomeRenderer.setDisplayChartValues(true);
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setXLabels(0);
multiRenderer.setBarSpacing(0.3f);
multiRenderer.setBarWidth(30);
multiRenderer.setChartTitle("Income Chart");
multiRenderer.setXTitle("Year 2013");
multiRenderer.setYTitle("Amount in Dollars");
//multiRenderer.setZoomLimits(1.0,0.7,1.0,3000.0);
multiRenderer.setZoomButtonsVisible(true);
//multiRenderer.setZoomEnabled(true, true);
//multiRenderer.setPanEnabled(true, true);
multiRenderer.setInScroll(true);
multiRenderer.setXAxisMin(0);
multiRenderer.setXAxisMax(7);
multiRenderer.setYAxisMin(0);
multiRenderer.setYAxisMax(4000);
multiRenderer.setClickEnabled(true);
multiRenderer.setShowGridX(true);
for (int i = 0; i < x.length; i++) {
multiRenderer.addXTextLabel(i, mMonth[i]);
}
multiRenderer.addSeriesRenderer(incomeRenderer);
return multiRenderer;
}
}
Logs:
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at org.achartengine.renderer.DefaultRenderer.getSeriesRendererAt(DefaultRenderer.java:189)
at org.achartengine.chart.XYChart.draw(XYChart.java:240)
at org.achartengine.GraphicalView.onDraw(GraphicalView.java:168)
This code works for my line graph,
v.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SeriesSelection seriesSelection = ((GraphicalView) v)
.getCurrentSeriesAndPoint();
Log.d("sreedhu", String.valueOf(seriesSelection));
if (seriesSelection == null) {
Log.d("sreedhu", "Nothing Selected");
} else {
//your code}
}
}
use this codes to zoom your barchart...!
renderer.setScale((float) 1);

Categories

Resources