Hello Friends!
Today i am going to share very simple code for Draw Bar Chart in Android.
*No Library needed.
*No Canvas needed.
Just copy paste below code and enjoy :)
Thanks!
You may like(Custom Bar Chart)-
http://www.androidhub4you.com/2013/05/custom-bar-chart-in-android-dynamic.html
Today i am going to share very simple code for Draw Bar Chart in Android.
*No Library needed.
*No Canvas needed.
Just copy paste below code and enjoy :)
1)Print Screen
2)MainActivity
package com.manish.barchartdemo; import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.view.View; import android.widget.LinearLayout; public class MainActivity extends Activity { LinearLayout linearChart; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); linearChart=(LinearLayout)findViewById(R.id.linearChart); drawChart(5); } public void drawChart(int count) { System.out.println(count); for (int k = 1; k <= count; k++) { View view = new View(this); view.setBackgroundColor(Color.parseColor("#ff6233")); view.setLayoutParams(new LinearLayout.LayoutParams(30, 400)); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view .getLayoutParams(); params.setMargins(5, 0, 0, 0); // substitute parameters for left,top, right, bottom view.setLayoutParams(params); linearChart.addView(view); } } }
3)activity_main
<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" > <LinearLayout android:id="@+id/linearChart" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/view" android:layout_marginTop="50dp" > </LinearLayout> <View android:id="@+id/view" android:layout_width="match_parent" android:layout_height="25dp" android:layout_alignParentBottom="true" android:background="#00FF00" /> </RelativeLayout>
You may like(Custom Bar Chart)-
http://www.androidhub4you.com/2013/05/custom-bar-chart-in-android-dynamic.html
can you tell me how i could plot a graph from a wave file..
ReplyDeletehi ,
ReplyDeletemanish chart not working , i am suresh from chennai can u give me a detail code...
please recheck ones because it is very simple and small demo and should work..And this is full code..
DeleteThis comment has been removed by the author.
ReplyDeletecan you help , how to create dynamic legend for charts
ReplyDeletehello dear how can possible define Linear layout inside relative layout it show error
ReplyDelete-->
Plze Tell Me
ReplyDeleteTa fea esa wbda
ReplyDeleteDon't waste your time. This code produces a single column in the view. Guess the "should work" statement is correct
ReplyDeleteDon't waste your time. This code produces a single column in the view. Guess the "should work" statement is correct
ReplyDelete