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);
}