Bar Graph through webservice - android

I am trying to make a bar graph through web service but I m getting a problem. The bar graph page is display but no bar is there. So please any one help me.
Thanks in advance....
MY Code Is Here :
Chart Activity
public class Chart_MainActivity extends Activity
{
/// EditText edt1, edt2;
// TextView txt_1;
Button btn;
ArrayList<String> result;
//String x,y;
String x = "", y = "";
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mainn);
// edt1 = (EditText) findViewById(R.id.edt1_date1);
// edt2 = (EditText) findViewById(R.id.edt_date2);
btn = (Button) findViewById(R.id.button_invoke);
result = new ArrayList<String>();
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// result.addAll(getTMSChart(edt1.getText().toString(), edt2.getText().toString()));
result.add(x);
result.add(y);
Intent in = new Intent(getApplicationContext(), NextActivity.class);
in.putExtra("gotonextpageX", result.get(0));
in.putExtra("gotonextpageY", result.get(1));
startActivity(in);
}
});}
private ArrayList<String> getTMSChart(String FromDate, String ToDate)
{
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://smartData/weight.asmx";
String METHOD = "weight";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
String x = "", y = "";
ArrayList<String> stringResult = new ArrayList<String>();
try
{
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
for (int j = 0; j < propertyCount; j++)
{
stringResult.add(table.getProperty("Name").toString());
stringResult.add(table.getProperty("Value").toString());
// stringResult.add(table.getPropertyAsString("Margin_Percent").toString());
// freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
}
}
}
catch (ArrayIndexOutOfBoundsException e)
{}
catch(Exception e)
{}
return stringResult;
} }
Next Activity :
public class NextActivity extends Activity
{
double x,y;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mainn1);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
x = extras.getDouble("gotonextpageX");
y = extras.getDouble("gotonextpageY");
}
else
{}
final GraphicalView gv =createIntent();
RelativeLayout rl=(RelativeLayout)findViewById(R.id.rlt);
rl.addView(gv);
}
public GraphicalView createIntent()
{
String[] titles = new String[] { "Orders profit"};
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] {x,x,x});
values.add(new double[] {y,y,y});
int[] colors = new int[] { Color.parseColor("#77c4d3")};
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(XYMultipleSeriesRenderer.Orientation.HORIZONTAL);
setChartSettings(renderer,"","Order number","Freight Rate",0.5,12.5, 0, 1000, Color.GREEN, Color.GREEN);
renderer.setXLabels(1);
renderer.setYLabels(5);
renderer.setPanEnabled(true, false);
/*renderer.addXTextLabel(1, "Jan");
renderer.addXTextLabel(2, "Feb");
renderer.addXTextLabel(3, "Mar");
renderer.addXTextLabel(4, "Apr");
renderer.addXTextLabel(5, "May");
renderer.addXTextLabel(6, "Jun");
*/
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
seriesRenderer.setDisplayChartValues(true);
}
final GraphicalView grfv = ChartFactory.getBarChartView(NextActivity.this, buildBarDataset(titles, values), renderer, BarChart.Type.DEFAULT);
return grfv;
}
protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors)
{
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setBarSpacing(1);
renderer.setMarginsColor(Color.parseColor("#0E120E"));
renderer.setXLabelsColor(Color.WHITE);
renderer.setYLabelsColor(0,Color.WHITE);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.parseColor("#000000"));
int length = colors.length;
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
r.setChartValuesSpacing(-90);
r.setChartValuesSpacing(15);
renderer.addSeriesRenderer(r);
}
return renderer;
}
protected XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> values)
{
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int length = titles.length;
for (int i = 0; i < length; i++)
{
CategorySeries series = new CategorySeries(titles[i]);
double[] v = values.get(i);
int seriesLength = v.length;
for (int k = 0; k < seriesLength; k++)
{
series.add(v[k]);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;
}
protected void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle,
String yTitle, double xMin, double xMax, double yMin, double yMax, int axesColor,int labelsColor)
{
renderer.setChartTitle(title);
renderer.setYLabelsAlign(Paint.Align.RIGHT);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setXAxisMin(xMin);
renderer.setXAxisMax(xMax);
renderer.setYAxisMin(yMin);
renderer.setYAxisMax(yMax);
renderer.setMargins(new int[] { 10, 65, 10, 15 });
renderer.setAxesColor(axesColor);
renderer.setLabelsColor(labelsColor);
} }
I got an unknown buffer error...plzzz help me

Next Activity :
Change below lines
x = extras.getString("gotonextpageX");
y = extras.getString("gotonextpageY");
to
x = Double.valueOf(extras.getString("gotonextpageX"));
y = Double.valueOf(extras.getString("gotonextpageY"));

Related

sometimes line doesn't shows on the graph- a chartengine

I have developed a application using a chart engine. and am using achartengine for drawing graphs.
I have drawn a graph using time chart. here dates are coming on x-axis and values on y axis. When the input dates are too long ie, if one date is jan-10 and 2nd date is apr 12 then the line between two points doesn't showing.
![enter image description here][there is another point on date jan 10 is there when we scroll we can see that but the line between point is not showing]1
this is code
public View getChartView(long startDate,long currentDate,int visibility)
{
String titles = "New tickets";
Date[]dateList = new Date[dates.length];
for(int i=0;i<dates.length;i++)
{
dateList[i]=convertDateFromString(dates[i]);
}
int[] colors = new int[] { Color.GREEN};
PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE};
XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
setChartSettings(renderer, "Project work status", "Date", "Tickets",startDate,
currentDate,yMin,yMax, Color.GRAY, Color.LTGRAY);
float textSize=context.getResources().getDimension(R.dimen.text_title_medium);
CustomTimeChart chart2 = new CustomTimeChart(
buildDateDataset(titles, dateList, values), renderer,context,visibility,textSize);
// TimeChart chart = new TimeChart(buildDateDataset(titles, dateList, values), renderer);
chart2.setDateFormat("dd,MMM");
final GraphicalView graphView = new GraphicalView(context, chart2);
graphView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
SeriesSelection ss = graphView.getCurrentSeriesAndPoint();
if(ss!=null)
{
long clickedDateSeconds = (long) ss.getXValue();
Date clickedDate = new Date(clickedDateSeconds);
WeightTrackingActivity.dateCal.setTime(clickedDate);
WeightTrackingActivity.weight = ss.getValue();
try {
clickedDate=formatter.parse(clickedDate.toString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(clickedDate.before(Funcs.getCurrentDateInDate()))
WeightTrackingActivity.btnRecordWeight.setText("Update weight");
else
WeightTrackingActivity.btnRecordWeight.setText(WeightTrackingActivity.weightBtnText);
}
else
{
WeightTrackingActivity.btnRecordWeight.setText(WeightTrackingActivity.weightBtnText);
WeightTrackingActivity.dateCal.setTime(new Date());
}
}
});
return graphView;
}
protected void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle,
String yTitle, double startDate, double currentDate, double yMin, double yMax, int axesColor,
int labelsColor) {
// renderer.setAxesColor(axesColor);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.WHITE);
renderer.setShowGrid(true);
renderer.setGridColor(Color.LTGRAY);
renderer.setShowLegend(false);
renderer.setMarginsColor(Color.WHITE);
// renderer.setPanEnabled(true, true);
renderer.setClickEnabled(true);
// renderer.setPanLimits(new double[]{yMin,yMax});
renderer.setZoomEnabled(true, false);
renderer.setLabelsTextSize(context.getResources().getDimension(R.dimen.text_title_medium));
renderer.setPointSize(5f);
renderer.setXAxisMin(startDate);
renderer.setXAxisMax(currentDate);
renderer.setXLabelsColor(Color.BLACK);
renderer.setXLabels(5);
renderer.setXLabelsPadding(2);
renderer.setYAxisMin(yMin);
renderer.setYAxisMax(yMax);
renderer.setYLabels(6);
renderer.setYLabelsColor(0, Color.WHITE);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setYLabelsPadding(2);
}
protected XYMultipleSeriesDataset buildDateDataset(String titles,Date[] xValues,
double[] yValues) {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
TimeSeries series = new TimeSeries(titles);
sortingValues(xValues,yValues);
for (int k = 0; k < xValues.length; k++) {
series.add(xValues[k], yValues[k]);
}
dataset.addSeries(series);
return dataset;
}
private void sortingValues(Date[] xValues, double[] yValues) {
for(int i=0;i<xValues.length;i++)
{
for(int j=0;j<xValues.length-1;j++)
{
if(xValues[i].before(xValues[j]))
{
Date d = xValues[i];
xValues[i]=xValues[j];
xValues[j]=d;
Double x=yValues[i];
yValues[i]=yValues[j];
yValues[j]=x;
}
}
}
}
protected XYMultipleSeriesRenderer buildRenderer(int[] colors, PointStyle[] styles) {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
setRenderer(renderer, colors, styles);
return renderer;
}
protected void setRenderer(XYMultipleSeriesRenderer renderer, int[] colors, PointStyle[] styles) {
renderer.setMargins(new int[] { 20, 40, 15, 20 });
int length = colors.length;
for (int i = 0; i < length; i++) {
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(colors[i]);
r.setPointStyle(styles[i]);
r.setFillPoints(true);
r.setLineWidth(3);
r.setDisplayChartValues(true);
r.setChartValuesTextSize(context.getResources().getDimension(R.dimen.text_title_small));
r.setDisplayChartValuesDistance(2);
FillOutsideLine fillOutsideLine=new FillOutsideLine(FillOutsideLine.Type.BELOW);
fillOutsideLine.setColor(Color.parseColor("#A3E0FF"));
r.addFillOutsideLine(fillOutsideLine);
renderer.addSeriesRenderer(r);
}
}
private Date convertDateFromString(String date) {
Date dateConverted = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
dateConverted = df.parse(date);
} catch ( ParseException e ) {
}
return dateConverted;
}
you can turn hardware acceleration off
android:hardwareAccelerated="false"
to disable it for a particular view (This worked for me)
try:
View.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
I've added this after rendering the graph but it should work everywhere.

combination of two bar chart and two line chart using aChartEngine in Android

below code to combine two bar and two line chart :
public class GraphCombination {
private Context context;
private String[] weekDays = new String[] { "Sunday", "Monday", "Tuesday",
"Wednesday", "Thrusday", "Friday", "Saturday" };
private XYSeriesRenderer lowestTempBarRenderer, highestTempBarRenderer,
lowestTempLineRenderer, highestTempLineRenderer;
private XYMultipleSeriesRenderer multiRenderer;
private int margins[] = { 50, 50, 50, 50 };
public GraphCombination(Context context) {
this.context = context;
}
public void drawChart() {
int days[] = { 0, 1, 2, 3, 4, 5, 6 };
double lowestTemp[] = { 23.5, 25.2, 27.8, 21.2, 26.3, 27.1, 22.6 };
double highestTemp[] = { 38.2, 39.4, 40.8, 36.1, 39.9, 41.1, 38.5 };
XYSeries lowestTempSeries = new XYSeries("Lowest Temperature");
XYSeries highestTempSeries = new XYSeries("Highest Temperature");
for (int i = 0; i < days.length; i++) {
lowestTempSeries.add(i, lowestTemp[i]);
highestTempSeries.add(i, highestTemp[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(highestTempSeries);
dataset.addSeries(lowestTempSeries);
dataset.addSeries(highestTempSeries);
dataset.addSeries(lowestTempSeries);
setLowestTempBarRenderer();
setHighestTempBarRenderer();
setLowestTempLineRenderer();
setHighestTempLineRenderer();
setMultiRenderer();
for (int i = 0; i < days.length; i++) {
multiRenderer.addXTextLabel(i, weekDays[i]);
}
multiRenderer.addSeriesRenderer(highestTempBarRenderer);
multiRenderer.addSeriesRenderer(lowestTempBarRenderer);
multiRenderer.addSeriesRenderer(highestTempLineRenderer);
multiRenderer.addSeriesRenderer(lowestTempLineRenderer);
Intent intent = ChartFactory.getCombinedXYChartIntent(context, dataset,
multiRenderer, new String[] { BarChart.TYPE, BarChart.TYPE,
LineChart.TYPE, LineChart.TYPE }, "Combined Chart");
context.startActivity(intent);
}
private void setLowestTempBarRenderer() {
lowestTempBarRenderer = new XYSeriesRenderer();
lowestTempBarRenderer.setColor(context.getResources().getColor(
R.color.lowTemp));
lowestTempBarRenderer.setFillPoints(true);
lowestTempBarRenderer.setLineWidth(1);
lowestTempBarRenderer.setChartValuesTextAlign(Align.RIGHT);
lowestTempBarRenderer.setChartValuesTextSize(15f);
lowestTempBarRenderer.setDisplayChartValues(true);
}
private void setHighestTempBarRenderer() {
highestTempBarRenderer = new XYSeriesRenderer();
highestTempBarRenderer.setColor(context.getResources().getColor(
R.color.highTemp));
highestTempBarRenderer.setFillPoints(true);
highestTempBarRenderer.setLineWidth(1);
highestTempBarRenderer.setChartValuesTextAlign(Align.RIGHT);
highestTempBarRenderer.setChartValuesTextSize(15f);
highestTempBarRenderer.setDisplayChartValues(true);
}
private void setMultiRenderer() {
multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setChartTitle("Bar Chart and Line Chart");
multiRenderer.setXTitle("Week Days");
multiRenderer.setYTitle("Temperature in celsius");
multiRenderer.setXAxisMin(-1);
multiRenderer.setXAxisMax(7);
multiRenderer.setYAxisMin(15);
multiRenderer.setYAxisMax(45);
multiRenderer.setLabelsTextSize(17f);
multiRenderer.setLegendTextSize(20f);
multiRenderer.setAxisTitleTextSize(25f);
multiRenderer.setMargins(margins);
multiRenderer.setChartTitleTextSize(30f);
multiRenderer.setApplyBackgroundColor(true);
multiRenderer.setBackgroundColor(context.getResources().getColor(
R.color.background));
multiRenderer.setYLabelsAlign(Align.RIGHT);
multiRenderer.setBarSpacing(1);
multiRenderer.setZoomButtonsVisible(false);
multiRenderer.setPanEnabled(false);
multiRenderer.setXLabels(0);
}
private void setLowestTempLineRenderer() {
lowestTempLineRenderer = new XYSeriesRenderer();
lowestTempLineRenderer.setColor(context.getResources().getColor(
R.color.lowTemp));
lowestTempLineRenderer.setFillPoints(true);
lowestTempLineRenderer.setLineWidth(3);
lowestTempLineRenderer.setChartValuesTextAlign(Align.CENTER);
lowestTempLineRenderer.setChartValuesTextSize(15f);
lowestTempLineRenderer.setDisplayChartValues(false);
}
private void setHighestTempLineRenderer() {
highestTempLineRenderer = new XYSeriesRenderer();
highestTempLineRenderer.setColor(context.getResources().getColor(
R.color.highTemp));
highestTempLineRenderer.setFillPoints(true);
highestTempLineRenderer.setLineWidth(3);
highestTempLineRenderer.setChartValuesTextAlign(Align.CENTER);
highestTempLineRenderer.setChartValuesTextSize(15f);
highestTempLineRenderer.setDisplayChartValues(false);
}
}
due to above code i got this type of graph :
and i want this type of graph :
so how to avoid overlapping in two bar chart..??
just change this one
for (int i = 0; i < days.length; i++) {
lowestTempSeries.add(i, lowestTemp[i]);
highestTempSeries.add(i, highestTemp[i]);
}
with this :
for (int i = 0, j = 0; i < days.length; i++, j += 2) {
lowestTempSeries.add(j, lowestTemp[i]);
highestTempSeries.add(j + 0.9, highestTemp[i]);
}
and also change this :
for (int i = 0; i < days.length; i++) {
multiRenderer.addXTextLabel(i, weekDays[i]);
}
with this :
for (int i = 0, j = 1; i < days.length; i++, j += 2) {
multiRenderer.addXTextLabel(j - 0.5, weekDays[i]);
}

I need to arrange the barcharts properly in android

Right now i am creating a barchart in android using AChartEngine.After getting run of my application,at-first the emulator is showing like the first below image. But i need to show like the second below image how to do this?
And also i need to change the color for the background and also i wanna change the bar-charts colors,
How to do these things?
I have tried these codes, but not working
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.GRAY);
Please find my sources for reference.
Chart.java
public class Chart extends Activity {
EditText edt1, edt2;
TextView txtv1;
Button btn;
Bundle data;
String[] orderNo = new String[10];
int[] freightRate = new int[10];
int[] marginPercent = new int[10];
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText) findViewById(R.id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getTMSChart(edt1.getText().toString(), edt2.getText().toString());
Intent intnt = new Intent(v.getContext(), BarGraphActivity.class);
intnt.putExtras(data);
startActivity(intnt);
}
});
}
public void getTMSChart(String FromDate, String ToDate)
{
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String METHOD = "GetTMSChart";
String NAMESPACE = "http://tempuri.org/";
String SOAP_ACTION = "http://tempuri.org/GetTMSChart";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate.trim());
request.addProperty("ToDate", ToDate.trim());
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
data = new Bundle();
for (int i = 0; i < tablesCount; i++) {
SoapObject table = (SoapObject) root.getProperty(i);
orderNo[i] = table.getPropertyAsString("Order_No");
freightRate[i] = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
marginPercent[i] = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
/*Toast.makeText(getApplicationContext(), "Order No:" + orderNo[i] + "\nFreigtRate:" + freightRate[i] + "\nMarginPc:" + marginPercent[i], Toast.LENGTH_SHORT).show();*/
}
data.putStringArray("orderno", orderNo);
data.putIntArray("freightrate", freightRate);
data.putIntArray("marginpercent", marginPercent);
data.putInt("count",tablesCount);
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} }}
BarGraphActivity.java
public class BarGraphActivity extends Activity{
String[] orderNo = new String[10];
int[] freightRate = new int[10];
int[] marginPercent = new int[10];
int count;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Bundle idata = getIntent().getExtras();
if (idata !=null)
{
orderNo = idata.getStringArray("orderno");
freightRate = idata.getIntArray("freightrate");
marginPercent = idata.getIntArray("marginpercent");
count = idata.getInt("count");
CategorySeries series = new CategorySeries("Order-FreightRate Graph");
for ( int i = 0; i < count; i++){
series.add(orderNo[i], freightRate[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series.toXYSeries());
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setDisplayChartValues(true);
//renderer.setChartValuesSpacing(1);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
for ( int i = 0; i < count; i++){
mRenderer.addXTextLabel(i+1, orderNo[i]);
}
mRenderer.setZoomButtonsVisible(true);
mRenderer.setBarSpacing(0.5);
Intent intent = ChartFactory.getBarChartIntent(getApplicationContext(), dataset, mRenderer, Type.DEFAULT);
startActivity(intent);
} } }
Thanks for your precious time!..
Hi if you want to change background color for your chart just use these methods
mrenderer.setApplyBackgroundColor(true);
mrenderer.setBackgroundColor(Color.parseColor("#898989")); // here you have to give hexa decimal code
mrenderer.setMarginsColor(Color.parseColor("#898989")); // here you have to give hexa decimal code
If you want to change your bar color means just do like this
int[] colors = new int[] { Color.parseColor("#DAE1EB"), Color.parseColor("#406193")};
int color_length = colors.length;
for (int i = 0; i < color_length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
r.setChartValuesSpacing(5);
mrenderer.addSeriesRenderer(r);
}
If you are creating multiple renderer means use different color for the dual bar. If you are creating single bar means give only one color. It will works.

Failed to pass values from the web service to the bar-chart for creating a bar-chart in android

actually i am attempting to create a bar-chart.But i am getting the x and y axis values from the web service by consuming it.
There is no problem on getting the values from the web service, but i have only doubts on passing those values to the bar-chart for creating a bar graph.
Because,after getting run of my emulator,i am providing the proper inputs,if i try to invoke the "Invoke" button,its just showing only the blank screen..But i need to draw a bar-chart.How to do this?
Suggestions please.....
thanks for your precious time!..
PLEASE FIND MY SOURCES FOR REFERENCE
Chart.java
public class Chart extends Activity
{
EditText edt1, edt2;
TextView txtv1;
Button btn;
int orderNo = 0;
int freightRate = 0;
int marginPercent;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText) findViewById(R.id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
getTMSChart(edt1.getText().toString(), edt2.getText().toString());
Intent intnt = new Intent(v.getContext(), BarGraphActivity.class);
intnt.putExtra("orderNo", orderNo);
intnt.putExtra("freightRate", freightRate);
//intnt.putExtra("marginPercent", marginPercent);
startActivity(intnt);
}
});
}
public void getTMSChart(String FromDate, String ToDate)
{
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String METHOD = "GetTMSChart";
String NAMESPACE = "http://tempuri.org/";
String SOAP_ACTION = "http://tempuri.org/GetTMSChart";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
for (int j = 0; j < propertyCount; j++)
{
// String ord = table.getPropertyAsString("");
orderNo = Integer.parseInt(table.getPropertyAsString("Order_No"));
freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
//marginPercent = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
Log.i("Order Number Check : ", ""+orderNo);
Log.i("Freight Rate Check : ", ""+freightRate);
}
}
} catch (Exception e)
{
}
}}
BarGraphACtivity.java
public class BarGraphActivity extends Chart
{
int[] x_axis;
int[] y_axis;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
x_axis = new int[1];
y_axis = new int[1];
x_axis[0] = getIntent().getIntExtra("orderNo", 0);
y_axis[0] = getIntent().getIntExtra("freightRate", 0);
DrawGraph();
}
public void DrawGraph()
{
String[] titles = new String[] { " Barcharts", "" };
List<int[]> values = new ArrayList<int[]>();
values.add(x_axis);
values.add(y_axis);
int[] colors = new int[] { Color.WHITE, Color.BLACK };
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(Orientation.HORIZONTAL);
setChartSettings(renderer, "some texts", " ", " ", 0, x_axis, 0, y_axis, Color.GRAY, Color.LTGRAY);
renderer.setXLabels(1);
renderer.addXTextLabel(2, "orderNo");
renderer.addYTextLabel(2, "freight");
renderer.setPanEnabled(true, false);
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
seriesRenderer.setDisplayChartValues(true);
}
ChartFactory.getBarChartIntent(this, buildBarDataset(titles, values), renderer, Type.DEFAULT);
}
public XYMultipleSeriesRenderer buildBarRenderer(int[] colors)
{
// creates a SeriesRenderer and initializes it with useful default values as well as colors
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(15);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
int length = colors.length;
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
renderer.addSeriesRenderer(r);
}
return renderer;
}
public void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle, String yTitle,
int xMin, int[] x_axis, int yMin, int[] y_axis, int axesColor, int labelsColor)
{
// sets lots of default values for this renderer
renderer.setChartTitle(title);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setXAxisMin(xMin);
renderer.setYAxisMin(yMin);
renderer.setAxesColor(axesColor);
renderer.setLabelsColor(labelsColor);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.GRAY);
}
public XYMultipleSeriesDataset buildBarDataset(String[] titles, List<int[]> values)
{
// adds the axis titles and values into the dataset
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int length = titles.length;
for (int i = 0; i < length; i++)
{
CategorySeries series = new CategorySeries(titles[i]);
int[] v = values.get(i);
int seriesLength = v.length;
for (int k = 0; k < seriesLength; k++)
{
series.add(v[k]);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;
}
}

Unable to show values in separate text views in android

I am consuming a web service by soap method from Android. And I am showing the values from that web service in to two separate text views on the next screen.
Here that web service is returning two values. But I'm only able to show one value from that web service in text view on the next screen.
But I need to show both values in two separate textview boxes on the next screen....
How can I do this?
Suggestions please..
NOTE :- The input value for that web service is for FromDate : 01/01/2012 and
for ToDate : 07/07/2012
Please find my sources for reference
Main_WB.java
public class Main_WB extends Activity
{
EditText edt1,edt2;
//TextView txt_1;
Button btn;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText)findViewById(R.id.editText1);
edt2 = (EditText)findViewById(R.id.editText2);
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
getTMSChart(edt1.getText().toString(),edt2.getText().toString());
Intent myint = new Intent(Main_WB.this,ResultActivity.class);
startActivity(myint);
}
});
}
private void getTMSChart(String FromDate,String ToDate)
{
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
String METHOD = "GetTMSChart";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject)(result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
// String[] ord = new String[propertyCount];
// String[] fre = new String[propertyCount];
// int[] fre = new int[propertyCount];
// int[] margin = new int[propertyCount];
for (int j = 0; j < propertyCount; j++)
{
String x,y;
// int orderNo = Integer.parseInt(table.getPropertyAsString("Order_No"));
// int freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
// int marginPercent = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
String orderNo = table.getPropertyAsString("Order_No");
String freight = table.getAttributeAsString("Freight_Rate");
x = orderNo.toString();
y = freight.toString();
Intent in = new Intent(getApplicationContext(),ResultActivity.class);
in.putExtra("gotonextpageX",x);
in.putExtra("gotonextpageY", y);
startActivity(in);
//ord[j] = orderNo;
// fre[j] = freightRate;
// margin[j]= marginPercent;
// x = orderNo.toString();
// y = fre.toString();
// Intent myIntent = new Intent(Main_WB.this, ResultActivity.class);
// myIntent.putExtra("gotonextpage", x);
// startActivity(myIntent);
// whatever you do with these values
}
}
}
catch (Exception e)
{
}
} }
ResultActivity.java
public class ResultActivity extends Activity
{
String x,y;
TextView txt1,txt2;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
x = extras.getString("gotonextpageX");
y = extras.getString("gotonextpageY");
}
else
{
}
txt1 = (TextView)findViewById(R.id.txtVw);
txt2 = (TextView)findViewById(R.id.txtVw2);
txt1.setText(x);
txt2.setText(y);
}}
Thanks for your precious time!..
Here check it out ...
public class Main_WB extends Activity {
EditText edt1, edt2;
// TextView txt_1;
Button btn;
ArrayList<String> result;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText) findViewById(R.id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn = (Button) findViewById(R.id.button1);
result = new ArrayList<String>();
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
result.addAll(getTMSChart(edt1.getText().toString(), edt2.getText().toString()));
Intent in = new Intent(getApplicationContext(), ResultActivity.class);
in.putExtra("gotonextpageX", result.get(0));
in.putExtra("gotonextpageY", result.get(1));
startActivity(in);
}
});
}
private ArrayList<String> getTMSChart(String FromDate, String ToDate) {
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
String METHOD = "GetTMSChart";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
String x = "", y = "";
ArrayList<String> stringResult = new ArrayList<String>();
try {
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++) {
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
for (int j = 0; j < propertyCount; j++) {
stringResult.add(table.getPropertyAsString("Order_No").toString());
stringResult.add(table.getPropertyAsString("Freight_Rate").toString());
}
}
} catch (Exception e) {
}
return stringResult;
}
}
And dont change your second class, this must work.

Categories

Resources