Android AChartEngine graphicalView share events - android

First i give my View show below. and give some explanation:
In my ViewGroup i have two GraphicalView, each of them share the same size space. Let's just call the chart above chartA and below one chartB.
Then i have some questions:
If i make a move a movement on chartA ,how could i make the chartB move just as my finger moving on chartB?
If i pinch on chartA can also chartB change auto?
I want to add some callback function to some points? Does ACE supports this?
I do not want to show numbers negative while user pinching.How can I make this point?
Last is my chart code:
mDataset.addSeries(series);
PointStyle style = PointStyle.CIRCLE;
renderer = buildRenderer(lineColor, style, true);
setChartSettings(renderer, "X", "Y", 0, 50, yMin, yMax, Color.WHITE,
Color.WHITE, title,chartColor);
GraphicalView chart = ChartFactory.getLineChartView(context, mDataset, renderer);
layout.addView(chart, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
HashMap map = new HashMap();
and the renderer:
protected XYMultipleSeriesRenderer buildRenderer(int color,
PointStyle style,
boolean fill) {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(color);
r.setPointStyle(style);
r.setFillPoints(fill);
r.setLineWidth(3);
renderer.addSeriesRenderer(r);
return renderer;
}
I random all the data i want.

You have to register a PanListener on your chartA and on every panApplied event, just do: rendererB.setXAxisMin(rendererA.getXAxisMin()); and the same for max X and for the Y axis and then call chartB.repaint();
Same as the above, just that you need to add a ZoomListener.
You can set a click listener: chartA.setOnClickListener();
Please reformulate into a separate question.
Also, see this code showing you how to use the above APIs.

Related

Achartengine zoom, pan and onClick events not working correctly after changing chart,

I am using achartengine to display charts in an Android app.
The app allows the user to display different datasets and different charts types depending on the selections they make from spinners.
My problem is this. The original chart displays correctly and all zoom, pan, and onClick events preform as expected. But when I remove the first chart and add another, the charts will not zoom or pan from touch and onClick will not return selected point data. The achartengine zoom and reset buttons still display and work as expected. To remove a chart and add another I have used different variations of the following code with the same results.
private void repaint() {
mchart1_LL_pie = (LinearLayout) this.findViewById(R.id.chart1_LL_pie);
if (mChart1_ChartView_pie != null) {
mchart1_LL_pie.removeView(mChart1_ChartView_pie);
}
mChart1_ChartView_pie = ChartFactory.getPieChartView(getApplicationContext(), mChart1_Pie_Series, mChart1_Pie_Renderer);
mchart1_LL_pie.addView(mChart1_ChartView_pie, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
I have also tried to remove all the renderers and clear the data series with the following code.
mChart1_Pie_Renderer.removeAllRenderers();
int size = mChart1_Pie_Series.getItemCount();
for (int i = 0; i < size; i++) {
mChart1_Pie_Series.remove(0);
And then display the chart with a rebuilt dataset and renderer using the following.
mChart1_ChartView_pie = ChartFactory.getPieChartView(getApplicationContext(), mChart1_Pie_Series, mChart1_Pie_Renderer);
The problem with this approach is that the next chart is not displayed until the display is touched. After the display is touched, the correct chart is displayed and all zoom, pan and onClick events work properly.
Has anyone experienced this problem? If so, how did you solve it?
Any help or suggestions would be greatly appreciated. Thank you
Don
I am doing an application with charts. I have an evolution chart with TimeSeries. I paste my function to draw the chart. It can help you :)
public void drawChart() {
mChartView = null;
mDataset = null;
mRenderer = null;
mDataset = new XYMultipleSeriesDataset();
mRenderer = new XYMultipleSeriesRenderer();
mRenderer.setAxisTitleTextSize(15);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.BLUE);
r.setFillPoints(true);
mRenderer.addSeriesRenderer(r);
mRenderer.setZoomEnabled(true);
mRenderer.setShowGrid(true);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setAxesColor(Color.BLACK);
mRenderer.setShowLegend(true);
mRenderer.setShowLabels(true);
mRenderer.setLabelsColor(Color.BLACK);
mRenderer.setBackgroundColor(Color.TRANSPARENT);
mRenderer.setYLabelsPadding(20);
mRenderer.setXLabelsPadding(7);
mRenderer.setYLabelsAlign(Align.LEFT);
mRenderer.setMarginsColor(Color.rgb(220, 220, 220));
mRenderer.setAxesColor(Color.BLACK);
mRenderer.setLabelsColor(Color.BLACK);
mRenderer.setXLabelsColor(Color.BLACK);
mRenderer.setYLabelsColor(0, Color.BLACK);
// mRenderer.setAxisTitleTextSize(30);
mRenderer.setGridColor(Color.BLACK);
mRenderer.setXRoundedLabels(false);
// mRenderer.setLabelsTextSize(25);
mRenderer.setYTitle(Config.getResource("PRICE") + "("
+ dto.getCurrencyCode() + ")");
mRenderer.setMargins(new int[] { 0, 60, 50, 0 });
mRenderer.setMarginsColor(Color.WHITE);
// mRenderer.setXTitle("Date");
mRenderer.setShowLegend(false);
mRenderer.setInScroll(true);
evolutionSecurity = new TimeSeries("");
mDataset.addSeries(evolutionSecurity);
fillDataEvolution(); //Get data into serie
mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer,
"dd-MM-yy");
LinearLayout layout = (LinearLayout) findViewById(R.id.graphe_evolution_rate_currency);
layout.addView(mChartView);
if (layout != null)
layout.removeAllViews();
layout.addView(mChartView);
mChartView.repaint();
mChartView = null;
}
Then when i select an another value in my spinner i call this method and the chart is redrawn correctly.

Formatting achartengine line graph

I am using achartengine, to plot a line graph. I am trying to customize it to have Y axis lines which pass through the values, and show the values on top. Does any one have any idea, how can I achieve an effect like this one :
Here is what I currently have :
And here is the code Snippet :
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series);
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setPointStyle(PointStyle.CIRCLE);
renderer.setFillPoints(true);
renderer.setColor(Color.WHITE);
renderer.setLineWidth(2f);
XYMultipleSeriesRenderer seriesRenderer = new XYMultipleSeriesRenderer();
seriesRenderer.addSeriesRenderer(renderer);
seriesRenderer.setLabelsTextSize(20); // Text size
seriesRenderer.setShowAxes(true); // show both axes
seriesRenderer.setShowLegend(false);
seriesRenderer.setShowGridX(true); // X grid helps identify values
seriesRenderer.setShowLabels(true); // See the values
seriesRenderer.setYLabelsAlign(Align.RIGHT);
seriesRenderer.setZoomButtonsVisible(false); // bye bye zoom
seriesRenderer.setXAxisMin(0);
seriesRenderer.setXAxisMax(10);
seriesRenderer.setTextTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/Lifestyle Rounded M54.ttf"));
seriesRenderer.setPointSize(10f);
seriesRenderer.setPanEnabled(true, false);
View view = ChartFactory.getLineChartView(context, dataset, seriesRenderer);
return view;
Any input will be highly appreciated.
You can add annotation that can be displayed wherever you need on the graph:
series.addAnnotation(text, x, y);

Basic AndroidPlot Bar Graph?

Looking for a basic "AndroidPlot" bar graph example.
A few people have contacted the developer via the site forum but he mentions he is still working on that tutorial.
However, he does link to a more in depth example to look at for now.
The problem is I can't figure out which parts render the bar graph vs. the other functionality, as I am obviously not familiar with the more complex parts of the library.
Can any one please help me with a basic structure of code for a bar graph, using AndroidPlot please?
Thank you.
I got it working like this with AChartEngine (setup, I use one renderer, with one dataset, it is an active changeing graph):
LinearLayout layout = (LinearLayout)findViewById(R.id.chart);
// setup dataset and renderer
dataset = new XYMultipleSeriesDataset();
renderer = new XYMultipleSeriesRenderer();
// configure renderer
renderer.setZoomEnabled(false, false);
renderer.setPanEnabled(false, false);
renderer.setYAxisMax(90);
renderer.setYAxisMin(0);
renderer.setXAxisMin(-1);
renderer.setBarSpacing(0.5);
renderer.setShowLegend(false);
renderer.setXLabels(0); // hides the default labels
renderer.setLabelsTextSize(15);
// create chart
mChartView = ChartFactory.getBarChartView(this, dataset, renderer, BarChart.Type.DEFAULT);
layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// add some data, so the chart shows
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.rgb(192, 192, 192));
renderer.addSeriesRenderer(r);
XYSeries c = new XYSeries("");
c.add(0,0);
dataset.addSeries(c);
Then later, render it again to liven it up (note I ripped some parts from my own code, it might not be complete):
// remove any bars that already exist
if (theAct.dataset.getSeriesCount() > 0) {
theAct.dataset.removeSeries(0);
}
XYSeries c = new XYSeries("");
// for some reason, the bar is very narrow, when only one bar is shown,
// when we use a negative spacing, the bar will be bigger
// i is the number of bars
if (i == 1) {
theAct.renderer.setBarSpacing(-0.8);
} else {
theAct.renderer.setBarSpacing(0.5);
}
// finish up and render!
theAct.renderer.setXAxisMax(i);
theAct.dataset.addSeries(c);
theAct.mChartView.zoomReset();
theAct.mChartView.repaint();

Android: How to create negative values in plots axis based on achartengine lib?

I want to create XY plot with positive and negative numbers on both axys. By default achartnegine shows negative values of series but the start popint is always zero^ graph start from zero and next nubmer is something like -50, -40 etc. I have tried to avoid this but haven;t succed yet. Could you please suggest the right approach?
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(seriesXY);
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
//renderer.setXAxisMin(-10f);
//renderer.setYAxisMin(-250f);
//renderer.setBarSpacing(SPACING);
//renderer.setRange(new double[] { -250d, 250d});
XYSeriesRenderer sRenderer = new XYSeriesRenderer();
sRenderer.setColor(Color.BLUE);
sRenderer.setFillBelowLine(false);
sRenderer.setChartValuesSpacing(SPACING);
sRenderer.setFillBelowLineColor(Color.WHITE);
sRenderer.setFillPoints(false);
renderer.addSeriesRenderer(sRenderer);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.WHITE);
renderer.setMarginsColor(Color.WHITE);
renderer.setAxesColor(Color.BLACK);
renderer.setXLabelsColor(Color.BLUE);
renderer.setYLabelsColor(0, Color.BLUE);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setYLabelsAlign(Align.RIGHT);
GraphicalView chartView = ChartFactory.getLineChartView(
getActivity(),
dataset, renderer);
plot.removeAllViews();
plot.addView(chartView, new LayoutParams(
LayoutParams.MATCH_PARENT, 200));
chartView.repaint();
I use LineChartView
The answer is that you cannot put the axis in the center of the chart with AChartEngine as it is out of the box.

How can we fit the chart on screen?

I am using aChart Engine, Zoom in and out functionality in it moves the chart away from the screen.I want to keep the Chart fit to screen. Is there any way to keep the chart visible on screen i.e. always fit it to visible portion ??
I am using this method :
private XYMultipleSeriesRenderer getLineRenderer(int[] lineColor, PointStyle[] styles) {
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxesColor(Color.BLUE);
renderer.setAxisTitleTextSize(16);
renderer.setChartTitle("Time");
renderer.setChartTitleTextSize(15);
renderer.setFitLegend(true);
renderer.setPanEnabled(true, true);
renderer.setYLabels(6);
renderer.setMargins(new int[] { 20, 30, 15, 0 });
renderer.setZoomButtonsVisible(true);
renderer.setBarSpacing(10);
renderer.setShowGrid(true);
renderer.setYAxisMin(Common.min - 1);
renderer.setYAxisMax(Common.max + 1);
XYSeriesRenderer rendererSeries = new XYSeriesRenderer();
rendererSeries.setColor(Color.RED);
renderer.addSeriesRenderer(rendererSeries);
rendererSeries.setFillPoints(true);
rendererSeries.setLineWidth(3);
return renderer;
}
You can use two things,
Either desable the Zoom functionality
renderer.setZoomEnabled(false, false);
or, Set Limits of for the Zoom
renderer.setZoomLimits(arg0); // arg0 = new double[]{-20,20,-20,20}; anything you want
I find out the solution to my query
renderer.setPanEnabled(false);
renderer.setPanEnabled(false, false);
It works fine
You can do either:
renderer.setPanEnabled(false);
or
renderer.setPanLimits(limits);

Categories

Resources