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);
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 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.
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);
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);
*/
}
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);
//...
//...