everywhere i look, the only information I can find says to ass them via the following code
series.addAnnotation("Hello!!", 1, 1);
However, When I try it in my code (with the proper series name) I get an error message that says addAnnotation is not supported. Can someone please clear this up for me? thanks!
You must download a recent version of the library. For example, get the night build from here.
In your code, replace the last line (the one where you return the chart view) with:
XYMultipleSeriesDataset dataset = buildBarDataset(titles, values);
XYSeries series = dataset.getSeriesAt(0);
series.addAnnotation("Vacation", 6, 30);
return ChartFactory.getBarChartView(context, dataset, renderer, Type.STACKED);
Here's the code...
public View getView(Context context) {
String[] titles = new String[] { "2008", "2007" };
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] { 240, 210, 60, 40 });
values.add(new double[] { htmlHelper.grec, htmlHelper.gwhite, htmlHelper.gim, htmlHelper.gfit });
int[] colors = new int[] { Color.rgb(255, 255, 255),
Color.rgb(25, 25, 112) };
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
switch (context.getResources().getDisplayMetrics().densityDpi) {
/* Done*/
case DisplayMetrics.DENSITY_XHIGH:
renderer.setAxisTitleTextSize(29);
renderer.setChartTitleTextSize(60);
renderer.setLabelsTextSize(29);
renderer.setLegendTextSize(50);
renderer.setChartValuesTextSize(40);
break;
/*done*/
case DisplayMetrics.DENSITY_HIGH:
renderer.setAxisTitleTextSize(15);
renderer.setChartTitleTextSize(47);
renderer.setLabelsTextSize(19);
renderer.setLegendTextSize(1);
renderer.setChartValuesTextSize(40);
break;
case DisplayMetrics.DENSITY_LOW:
renderer.setAxisTitleTextSize(24);
renderer.setChartTitleTextSize(25);
renderer.setLabelsTextSize(9);
renderer.setLegendTextSize(10);
renderer.setChartValuesTextSize(20);
break;
default:
renderer.setAxisTitleTextSize(39);
renderer.setChartTitleTextSize(35);
renderer.setLabelsTextSize(20);
renderer.setLegendTextSize(2);
renderer.setChartValuesTextSize(40);
break;
}
setChartSettings(renderer, "Gym Attendance", "", "", 0.5, 12.5, 0,
24000, Color.BLACK, Color.BLACK);
renderer.getSeriesRendererAt(0).setDisplayChartValues(false);
renderer.getSeriesRendererAt(1).setDisplayChartValues(true);
renderer.setShowLegend(false);
renderer.setMargins(new int[] { 80, 10, 60, 10 });
renderer.addXTextLabel(1, "Rec. Hall" + "\n" + ce);
renderer.addXTextLabel(2, "White" + "\n" + "Building" + "\n"
+ wh);
renderer.addXTextLabel(3, "IM" + "\n" + "Building" + "\n" + imm);
renderer.addXTextLabel(4, "Fitness Loft" + "\n" + fi);
renderer.setXLabelsColor(Color.rgb(0, 0, 0));
renderer.setYLabelsColor(0, Color.BLACK);
renderer.setYLabels(10);
renderer.setXLabels(0);
renderer.setXAxisMin(0);
renderer.setXAxisMax(5);
renderer.setYAxisMin(0);
renderer.setYAxisMax(250);
renderer.setAxesColor(Color.BLACK);
renderer.setXLabelsAlign(Align.CENTER);
renderer.setYLabelsAlign(Align.LEFT);
renderer.setPanEnabled(false, false);
// renderer.setZoomEnabled(false);
renderer.setZoomRate(1.1f);
renderer.setBarSpacing(0.5f);
renderer.setApplyBackgroundColor(true);
renderer.getSeriesRendererAt(1).setGradientEnabled(true);
renderer.getSeriesRendererAt(1).setGradientStart(0,
Color.rgb(192, 192, 192));
renderer.getSeriesRendererAt(1).setGradientStop(45,
Color.rgb(25, 25, 112));
renderer.setBackgroundColor(Color.rgb(220, 220, 220));
renderer.setMarginsColor(Color.rgb(248, 248, 255));
renderer.setOrientation(Orientation.HORIZONTAL);
renderer.setZoomEnabled(false, false);
return ChartFactory.getBarChartView(context,
buildBarDataset(titles, values), renderer, Type.STACKED);
}
Thanks so much for taking a look! At first I had the graph in frame layout with textviews but that doesn't work once I started testing on different screen sizes and pixel densities.