0

I've been playing around with AchartEngine for a couple of days now. I modified the TrignometricFunctionsChart to display all sorts of graphs possible. Now I want the user to type in the function and plot a graph for that function. For that I need an EditText and a Button inside chart. I tried reading Android: I am using AChartEngine library for graphs, but not able to integrate achartengine's graph view with android xml? yet couldn't accomplish the task. I tried editing the XYChartBuilder (the only chart with accommodated in an XML file) but couldn't insert the TrignometricFunctionsChart into it.

I don't know how to migrate this snippet of code:

public Intent execute(Context context) {
String[] titles = new String[] { "sin", "cos" };
List<double[]> x = new ArrayList<double[]>();
List<double[]> values = new ArrayList<double[]>();
int step = 4;
int count = 360 / step + 1;
x.add(new double[count]);
x.add(new double[count]);
double[] sinValues = new double[count];
double[] cosValues = new double[count];
values.add(sinValues);
values.add(cosValues);
for (int i = 0; i < count; i++) {
  int angle = i * step;
  x.get(0)[i] = angle;
  x.get(1)[i] = angle;
  double rAngle = angle/57.295779513082;
  sinValues[i] = rAngle;
  cosValues[i] = 0.25*rAngle;
}
int [] colors = new int[] { Color.BLUE, Color.CYAN };
PointStyle[] styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT };
XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
setChartSettings(renderer, "Trigonometric functions", "X (in degrees)", "Y", 0, 360, -1, 1,
    Color.GRAY, Color.LTGRAY);
renderer.setXLabels(20);
renderer.setYLabels(10);
return ChartFactory.getLineChartIntent(context, buildDataset(titles, x, values), renderer);
}
Community
  • 1
  • 1
Adnan Zahid
  • 573
  • 1
  • 10
  • 38

1 Answers1

0

The best place to start with embedding a chart into a layout is exactly the one you mentioned. I would suggest reading the demo code more carefully.

Make sure you understand how the demo chart inherit behavior from their parent class. For instance, the buildRenderer(), buildDataset() and others are all located in AbstractDemoChart.

Dan D.
  • 32,246
  • 5
  • 63
  • 79
  • I tried alot my friend. As I've mentioned I even modified the code to display graphs of complex functions. The only thing I couldn't comprehend was how to insert the above code into XYChartBuilder. – Adnan Zahid Aug 03 '12 at 13:38