I have a simple TimeChart in AChartEngine, everything works good but i have no idea how to add second series. Every my try was ended by ANR. Have you got any ideas how to add another series? This is my code:
EDIT: I changed code, i tried add second line but i have ANR:
public class TestgrafActivity extends Activity {
private XYMultipleSeriesDataset mDataset;
private XYMultipleSeriesRenderer mRenderer;
List<double[]> values = new ArrayList<double[]>();
private GraphicalView mChartView;
private TimeSeries time_series,time_series2;
private LinearLayout layout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
layout = (LinearLayout) findViewById(R.id.chart);
time_series = new TimeSeries("Temperature");
for (int i = 0; i < 50; i++){
long value = new Date().getTime();
time_series.add(new Date(value+(i*1000)), new Random().nextInt(25));
}
time_series2 = new TimeSeries("Temperature2");
for (int i = 0; i < 50; i++){
long value = new Date().getTime();
time_series2.add(new Date(value+(i*1000)), new Random().nextInt(40));
}
mDataset = new XYMultipleSeriesDataset();
mDataset.addSeries(time_series);
mDataset.addSeries(time_series2);
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.GREEN);
r.setPointStyle(PointStyle.CIRCLE);
r.setFillPoints(true);
r.setLineWidth(3);
r.setDisplayChartValues(true);
XYSeriesRenderer r2 = new XYSeriesRenderer();
r2.setColor(Color.RED);
r2.setPointStyle(PointStyle.CIRCLE);
r2.setFillPoints(true);
r2.setLineWidth(3);
r2.setDisplayChartValues(true);
mRenderer = new XYMultipleSeriesRenderer();
mRenderer.addSeriesRenderer(r);
mRenderer.addSeriesRenderer(r2);
mRenderer.setAxisTitleTextSize(16);
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setPointSize(3f);
mRenderer.setPanEnabled(true, true);
mRenderer.setZoomEnabled(true, true);
mRenderer.addSeriesRenderer(r2);
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(20);
mRenderer.setPanEnabled(true);
mRenderer.setChartTitle("Temperature");
mRenderer.setXTitle("Time");
mRenderer.setYTitle("Degrees C");
mRenderer.setZoomButtonsVisible(true);
mRenderer.setZoomEnabled(true);
mRenderer.setXLabels(12);
mRenderer.setYLabels(10);
mRenderer.setShowGrid(true);
mRenderer.setXLabelsAlign(Align.RIGHT);
mRenderer.setYLabelsAlign(Align.RIGHT);
mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer,
"HH:mm:ss");
layout.addView(mChartView);
}
}
You have only one Series in this code. Where is the code where you try to add another series?
The general approach is this:
mDataset.addSeries(0, time_series);
mRenderer.addSeriesRenderer(0, time_renderer);
//...
//...
mDataset.addSeries(1, some_other_series);
mRenderer.addSeriesRenderer(1, some_other_renderer);
//...
//...
Related
I want to use graph in widget. Like This! I want to make graph using AchartEngine. Graph using AchartEngine is working in normal app but how to implement it in widget?
Here is My code:
public class MainActivity extends ActionBarActivity {
private XYMultipleSeriesDataset mDataset = getDemoDataset();
private XYMultipleSeriesRenderer mRenderer = getDemoRenderer();
private GraphicalView mChartView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRendererStyling();
if (mChartView == null) {
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getLineChartView(MainActivity.this,
mDataset, mRenderer);
mRenderer.setSelectableBuffer(100);
layout.addView(mChartView, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
} else {
mChartView.repaint();
}
}
private void setRendererStyling() {
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
mRenderer.setAxisTitleTextSize(16);
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
mRenderer.setZoomButtonsVisible(true);
mRenderer.setPointSize(8);
}
private XYMultipleSeriesRenderer getDemoRenderer() {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setMargins(new int[] { 20, 30, 15, 0 });
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.BLUE);
r.setPointStyle(PointStyle.SQUARE);
// r.setFillBelowLine(true);
// r.setFillBelowLineColor(Color.WHITE);
r.setFillPoints(true);
renderer.addSeriesRenderer(r);
r = new XYSeriesRenderer();
r.setPointStyle(PointStyle.CIRCLE);
r.setColor(Color.GREEN);
r.setFillPoints(true);
renderer.addSeriesRenderer(r);
renderer.setAxesColor(Color.DKGRAY);
renderer.setLabelsColor(Color.LTGRAY);
return renderer;
}
private XYMultipleSeriesDataset getDemoDataset() {
double[] seriesFirstY = { 20, -20, 63, 150, -49, 24, 91, -34, -8 };
double[] seriesSecondY = { 10, 70, -40, -20, 130, 24, 167, -34, 80 };
double[] seriesFirstX = { 0, 8, 14, 20, 35, 40, 56, 80, 109 };
double[] seriesSecondX = { 0, 24, 67, 75, 95, 134, 149, 168, 180 };
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
XYSeries firstSeries = new XYSeries("series One");
for (int i = 0; i < 9; i++)
firstSeries.add(seriesFirstX[i], seriesFirstY[i]);
dataset.addSeries(firstSeries);
XYSeries secondSeries = new XYSeries("series Two");
for (int j = 0; j < 9; j++)
secondSeries.add(seriesSecondX[j], seriesSecondY[j]);
dataset.addSeries(secondSeries);
return dataset;
}
I want to use Above code in widget app. Please help me.!!
public class MainActivity extends AppWidgetProvider {
private XYMultipleSeriesDataset mDataset = getDemoDataset();
private XYMultipleSeriesRenderer mRenderer = getDemoRenderer();
private GraphicalView mChartView;
#SuppressLint("NewApi")
#SuppressWarnings("deprecation")
#Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
int currentWidgetId = appWidgetIds[i];
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.activity_main);
setRendererStyling();
if (mChartView == null) {
LayoutInflater inflater = LayoutInflater.from(context);
View rowView = inflater.inflate(R.layout.second, null, true);
LinearLayout layout = (LinearLayout) rowView
.findViewById(R.id.chart);
mChartView = ChartFactory.getLineChartView(context, mDataset,
mRenderer);
mRenderer.setSelectableBuffer(100);
layout.addView(mChartView, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// views.apply(context, layout);
views.setImageViewBitmap(R.id.img_view,
layout.getDrawingCache());
appWidgetManager.updateAppWidget(currentWidgetId, views);
Toast.makeText(context, "widget added", Toast.LENGTH_SHORT)
.show();
} else {
mChartView.repaint();
}
}
}
}
I tried this code, but its does not work... Please help me.
I am using achartengine jar for Bar graph view. My requirement of Bar Graph design example diagram has attached below.
The top Image is My requiremnt bar graph
The Bottom Image is my output image.
My code is:
public class TestClass extends AppCompatActivity {
private GraphicalView BarChartView;
#SuppressLint("ParserError")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_graph);
if (BarChartView==null )
{
XYMultipleSeriesRenderer renderer = buildBarRenderer();
setChartSettings(renderer);
BarChartView = ChartFactory.getBarChartView(this, getBarDataset(), renderer, Type.DEFAULT);
LinearLayout playout = (LinearLayout) findViewById(R.id.graph2);
playout.addView(BarChartView);
} else
{
BarChartView.repaint();
BarChartView.setVisibility(View.GONE);
}
}
private void setChartSettings(XYMultipleSeriesRenderer renderer)
{
renderer.setYTitle("Hits");
renderer.setXAxisMin(0);
renderer.setXAxisMax(7);
renderer.setYAxisMin(0);
renderer.setYAxisMax(100);
}
private XYMultipleSeriesDataset getBarDataset()
{
XYSeries series1 = new XYSeries("A");
XYSeries series2 = new XYSeries("B");
XYSeries series3 = new XYSeries("C");
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
series1.add(3, 50);
dataset.addSeries(series1);
series2.add(4, 25);
dataset.addSeries(series2);
series3.add(5, 100);
dataset.addSeries(series3);
return dataset;
}
protected XYMultipleSeriesRenderer buildBarRenderer() {
XYMultipleSeriesRenderer mrenderer = new XYMultipleSeriesRenderer();
//double[] range = {5,5,0};
mrenderer.setAxisTitleTextSize(16);
mrenderer.setChartTitleTextSize(20);
mrenderer.setLabelsTextSize(15);
mrenderer.setLegendTextSize(15);
mrenderer.setBarSpacing(0.5);
mrenderer.setXLabels(0);
mrenderer.addXTextLabel(0, "SAVINGS TOTAL");
mrenderer.addXTextLabel(1.5, "SPEND BREAKDOWN");
mrenderer.addXTextLabel(3, "DEPT");
mrenderer.setMargins(new int[]{20, 30, 15, 0});
mrenderer.setAxesColor(Color.WHITE);
mrenderer.setChartTitle("");
mrenderer.setXTitle("");
// mrenderer.setInitialRange(range, 1);
mrenderer.setBarWidth(100);
XYSeriesRenderer renderer1 = new XYSeriesRenderer();
renderer1.setColor(Color.GREEN);
XYSeriesRenderer renderer2 = new XYSeriesRenderer();
renderer2.setColor(Color.RED);
XYSeriesRenderer renderer3 = new XYSeriesRenderer();
renderer3.setColor(Color.BLUE);
mrenderer.addSeriesRenderer(renderer1);
mrenderer.addSeriesRenderer(renderer2);
mrenderer.addSeriesRenderer(renderer3);
return mrenderer;
}
}
Kindly Please help me solve the Bar Grapg dotted line between x and Y axis.
If any one have idea please le me know. Thanks in advance.
use
renderer.setStroke(BasicStroke.DASHED);
or
renderer.setStroke(BasicStroke.DOTTED);
I modified the sample code because I need to get a pie chart that is updated continuously. I managed to do some work but I can not figure out how to refresh the graph. This is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
ButtonInit();
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);
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();
}
}
#Override
protected void onResume() {
super.onResume();
LinearLayout layout = (LinearLayout) findViewById(R.id.Graph);
mChartView = (GraphicalView) ChartFactory.getPieChartView(this, mSeries, mRenderer);
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(10);
layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mChartView.repaint();
}
variables a, b​​, c, d are constantly changing because I get them via bluetooth.
Try doing this way
private GraphicalView mChart;
LinearLayout chart_container = (LinearLayout) findViewById(R.id.graphHolder);
.........
.......
mChart = (GraphicalView) ChartFactory.getPieChartView(this, dataset,
mRenderer);
chart_container.addView(mChart);
Now you can use
mChart.repaint();
I want to display graph using Achartengine in Fragment.
In my layout file I have used empty linear layout to add graph returned by createIntent() method
but it only shows blank screen
I am using following code
My Fragment activity is as below
pls help
public class Analytics_Screen extends Fragment implements OnClickListener,SlideActivity.Callbacks{
View checkanalytics_view;
SlideActivity activity;
LinearLayout graph_container;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
activity = (SlideActivity) getActivity();
metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
if (checkanalytics_view == null)
{
checkanalytics_view = inflater.inflate(R.layout.checkanalytics_screen, null, false);
}
activity.OpenLeftmenu(0);
SlideActivity.registerCallback(this);
graph_container = (LinearLayout)checkanalytics_view.findViewById(R.id.graph_container);
final GraphicalView gv =createIntent();
graph_container.addView(gv,new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
return checkanalytics_view;
}
public GraphicalView createIntent()
{
// List<double[]> values = new ArrayList<double[]>();
System.out.println("==============create Intent Start==========================");
List<Double> dValues=new ArrayList<Double>();
dValues.add((double) 5000);
dValues.add((double) 6000);
dValues.add((double) 7000);
dValues.add((double) 8000);
dValues.add((double) 10000);
dValues.add((double) 5000);
dValues.add((double) 25000);
dValues.add((double) 50000);
dValues.add((double) 50000);
// values.add(new double[] { 5000, 7300, 9240,10230, 11300, 10040,14230, 12300, 14240});
int[] colors = new int[] { Color.parseColor("#77c4d3")};
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(Orientation.VERTICAL);
setChartSettings(renderer, "Analitics", "", "",0.1,
12.5, 0,50000, Color.BLACK, Color.BLACK);
renderer.setXLabels(1);
renderer.setYLabels(10);
renderer.addXTextLabel(1, "Male");
renderer.addXTextLabel(2, "Female");
renderer.addXTextLabel(3, "Age 0-20");
renderer.addXTextLabel(4, "Age 21-30");
renderer.addXTextLabel(5, "Age 31-40");
renderer.addXTextLabel(6, "Age 41-50");
renderer.addXTextLabel(7, "Age 50+");
renderer.addXTextLabel(8, "Penciled");
renderer.addXTextLabel(9, "Attended");
/* renderer.addXTextLabel(10, "Oct");
renderer.addXTextLabel(11, "Nov");
renderer.addXTextLabel(12, "Dec");*/
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++) {
SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
seriesRenderer.setDisplayChartValues(true);
}
final GraphicalView grfv = ChartFactory.getBarChartView(activity, buildBarDataset(dValues), renderer,Type.DEFAULT);
System.out.println("===============Graph View=================="+grfv);
return grfv;
}
protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors) {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(10);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(10);
renderer.setLegendTextSize(5);
renderer.setBarSpacing(1);
renderer.setMarginsColor(Color.parseColor("#EEEDED"));
renderer.setXLabelsColor(Color.BLACK);
renderer.setYLabelsColor(0,Color.BLACK);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.parseColor("#FBFBFC"));
renderer.setInScroll(true);
int length = colors.length;
Log.d("Color Len",""+length);
for (int i = 0; i < length; i++) {
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
// r.setChartvalueAngle(-90);
r.setChartValuesSpacing(25);
renderer.addSeriesRenderer(r);
}
return renderer;
}
protected XYMultipleSeriesDataset buildBarDataset(List<Double> values) {
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
CategorySeries series = new CategorySeries("Amount");
// Double v = values.get(0);
int seriesLength = values.size();
for (int k = 0; k < seriesLength; k++) {
series.add(values.get(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(Align.RIGHT);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setXAxisMin(xMin);
renderer.setXAxisMax(xMax);
renderer.setYAxisMin(yMin);
renderer.setYAxisMax(yMax);
renderer.setMargins(new int[] {15,50,50,50 });
renderer.setAxesColor(axesColor);
renderer.setLabelsColor(labelsColor);
}
Use this instead
protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors)
{
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(10);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(10);
renderer.setLegendTextSize(5);
renderer.setBarSpacing(1);
renderer.setMarginsColor(Color.parseColor("#EEEDED"));
renderer.setXLabelsColor(Color.BLACK);
renderer.setYLabelsColor(0, Color.BLACK);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.parseColor("#FBFBFC"));
renderer.setInScroll(true);
int length = colors.length;
Log.d("Color Len", "" + length);
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(colors[0]);
// r.setChartvalueAngle(-90);
// r.setChartValuesSpacing(25);
renderer.addSeriesRenderer(r);
return renderer;
}
I am not sure if my answer can solve your problem, but I was successful in displaying a graph in a fragment. This is what I did, following is my fragment Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4DDBFF">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/graphLayout"
android:background="#000000" />
</LinearLayout>
I created 2 classes (a)SideFragment.java (b) LineGraph.java
LineGraph.java generates the graph and the following method return the view in this class
public GraphicalView getView(Context context){
GraphicalView view = ChartFactory.getLineChartView(context, mDataset, mRenderer);
return view;
}
In SideFragment.java I have a GraphicalView variable which is initialised in onCreate() by calling LineGraph.getView() as follows
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getActivity().getApplicationContext();
line = new LineGraph();
graphview = line.getView(context);
}
And I add this Graphview is attached to the fragment Layout in onStart()
public void onStart() {
super.onStart();
Log.i(TAG, "onStart");
LinearLayout fragmentLayout = (LinearLayout) view.findViewById(R.id.graphLayout);
fragmentLayout.addView(graphview);
}
Since I am generating the graph dynamically I keep repainting the GraphView on a background thread (AsyncTask) which I have initiated in onActivityCreated()
protected void onProgressUpdate(String... values) {
Log.i(TAG, "onProgressUpdate");
graphview.repaint();
super.onProgressUpdate(values);
}
I hope this could be of some help to you.
I am using for achartengine for drawing a line graph for show blood
sugar at date wise.
I successfully drawn the line graph.
but, I am struggling here for , some time i am having more that one values per day
for blood sugar checking.
I dont know for, how to show a multiple values in line graph at same date.
Thanks Advance..
Note: I need to show the line graph for multiple values each day. Normally Blood
sugar possible for checking for minimum 3 times per day.
that's my problem.
My Code : my code is very usefull for normal line graph generating..
public class GraphActivity extends Activity {
private ArrayList<String> mMonthArrayList = new ArrayList<String>() ;
private GraphicalView mChart ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(), "SecondActivity", 20).show();
mMonthArrayList.add("01/01/2013");
mMonthArrayList.add("02/01/2013");
mMonthArrayList.add("03/01/2013");
mMonthArrayList.add("04/01/2013");
mMonthArrayList.add("05/01/2013");
mMonthArrayList.add("06/01/2013");
mMonthArrayList.add("07/01/2013");
mMonthArrayList.add("08/01/2013");
mMonthArrayList.add("09/01/2013");
mMonthArrayList.add("10/01/2013");
mMonthArrayList.add("11/01/2013");
mMonthArrayList.add("12/01/2013");
openChart();
}
private void openChart()
{
int xsideData[] = {0,2,3,4,6};
int ysideData[] = {200,300,500,600,400};
/*ArrayList<Integer> xsideData = new ArrayList<Integer>() ;
xsideData.add(0);
xsideData.add(1);
xsideData.add(2);
xsideData.add(3);
xsideData.add(4);
ArrayList<Integer> ysideData = new ArrayList<Integer>() ;
ysideData.add(200);
ysideData.add(300);
ysideData.add(400);
ysideData.add(600);
ysideData.add(800);*/
XYSeries xyseriesData = new XYSeries("XYSERIES TITLE");
XYSeriesRenderer xyRenderer = new XYSeriesRenderer() ;
XYMultipleSeriesDataset xymultipleDataset = new XYMultipleSeriesDataset();
// Adding data to xside and yside Series
for(int i = 0 ; i < xsideData.length; i++ ) {
xyseriesData.add(xsideData[i], ysideData[i]);
}
xymultipleDataset.addSeries(xyseriesData);
xyRenderer.setColor(Color.WHITE);
xyRenderer.setPointStyle(PointStyle.CIRCLE);
xyRenderer.setFillPoints(true);
xyRenderer.setLineWidth(1);
xyRenderer.setDisplayChartValues(true);
// Creating a XYMultipleSeriesRenderer to customize the whole chart
XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
multiRenderer.setXLabels(0);
multiRenderer.setXTitle("Year 2012");
//multiRenderer.setZoomButtonsVisible(true);
multiRenderer.setGridColor(Color.WHITE);
multiRenderer.setShowGrid(true);
multiRenderer.setLabelsTextSize(15);
multiRenderer.setLegendTextSize(15);
multiRenderer.setMargins(new int[] { 20, 30, 15, 0 });
multiRenderer.setXLabels(7);
multiRenderer.setYLabels(5);
multiRenderer.setDisplayChartValues(false);
//multiRenderer.setShowGrid(false);
for(int i=0;i<xsideData.length;i++)
{
multiRenderer.addXTextLabel(i, mMonthArrayList.get(i));
}
multiRenderer.addSeriesRenderer(xyRenderer);
LinearLayout chartContainer = (LinearLayout) findViewById(R.id.chart_container);
// Creating a Line Chart
mChart = (GraphicalView) ChartFactory.
getLineChartView(getBaseContext(), xymultipleDataset, multiRenderer);
// Adding the Line Chart to the LinearLayout
chartContainer.addView(mChart);
}
}
My output image :
![enter image description here][1]
Have a look at this code... It works fine
public class NewGraph extends Activity
{
private XYMultipleSeriesDataset mDataset;
private XYMultipleSeriesRenderer mRenderer;
List<double[]> values = new ArrayList<double[]>();
private GraphicalView mChartView;
private TimeSeries time_series;
// chart container
private LinearLayout layout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testlayout);
layout = (LinearLayout) findViewById(R.id.chart);
// create dataset and renderer
mDataset = new XYMultipleSeriesDataset();
mRenderer = new XYMultipleSeriesRenderer();
mRenderer.setAxisTitleTextSize(16);
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setPointSize(3f);
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.GREEN);
r.setPointStyle(PointStyle.CIRCLE);
r.setFillPoints(true);
mRenderer.addSeriesRenderer(r);
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(20);
mRenderer.setPanEnabled(true);
time_series = new TimeSeries("test");
mDataset.addSeries(time_series);
fillData();
int pos=time_series.getItemCount();
Log.v("newgraph", "pos"+pos);
mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer,
"dd-MMM-yyyy");
layout.addView(mChartView);
}
private void fillData()
{
// long value = new Date().getTime() - 3 * TimeChart.DAY;
final Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 10);
long mytimestamp1=c.getTimeInMillis();
c.set(Calendar.HOUR_OF_DAY, 11);
long mytimestamp2=c.getTimeInMillis();
c.set(Calendar.HOUR_OF_DAY, 12);
long mytimestamp3=c.getTimeInMillis();
c.set(Calendar.HOUR_OF_DAY, 13);
long mytimestamp4=c.getTimeInMillis();
c.set(Calendar.HOUR_OF_DAY, 14);
long mytimestamp5=c.getTimeInMillis();
c.set(Calendar.HOUR_OF_DAY, 15);
long mytimestamp6=c.getTimeInMillis();
c.set(Calendar.HOUR_OF_DAY, 16);
c.add(Calendar.DATE, 1);
c.set(Calendar.HOUR_OF_DAY,12);
long mytimestamp7=c.getTimeInMillis();
time_series.add(mytimestamp1, 10);
time_series.add(mytimestamp2, 20);
time_series.add(mytimestamp3, 30);
time_series.add(mytimestamp4, 40);
time_series.add(mytimestamp5, 50);
time_series.add(mytimestamp6, 60);
time_series.add(mytimestamp7,30);
/*time_series.add(new Date(mytimestamp1), 10);
time_series.add(new Date(mytimestamp2), 20);
time_series.add(new Date(mytimestamp3), 30);
time_series.add(new Date(mytimestamp4), 40);
time_series.add(new Date(mytimestamp5), 50);
time_series.add(new Date(mytimestamp6), 60);
*/
}