JSHeb
JSHeb

Reputation: 113

Achartengine : reverse plot

I'm using achartengine in my Android Application, it works well but i have a question.

Is it possible to reverse plot?

I mean in my graph, new values which are added to my XY series with the function add, are added at end of the series, and then the graph is redrawn, so new values appears at right of the graph.

But i want to add my new value at index 0, in order to show on the graph only the last X values.

enter image description here

Sorry if it's not very clear

Thanks

Upvotes: 2

Views: 625

Answers (2)

JSHeb
JSHeb

Reputation: 113

So, i've found a trick:

Dataset is my XYseries and mRenderer my multipleSeriesRenderer

  • I've changed alignment of the Y axis:

mRenderer.setYAxisAlign(Align.RIGHT, 0);

  • I've erased automatic labels:

mRenderer.setXLabels(0);

  • The 0 on the axe X is now a custom label, so every time a new value is added to the graph, I have to change is position:

mRenderer.setXAxisMax(dataset.getItemCount() - 1); mRenderer.addXTextLabel(dataset.getItemCount() - 1, "0");

  • And to finish, i change the X axis min everytime a new value is added, in order to get a fix scale:

mRenderer.setXAxisMin(dataset.getItemCount() - scale - 1);

enter image description here

Upvotes: 0

Dan D.
Dan D.

Reputation: 32391

There is no support for inserting data to XYSeries at a given index. However you could get to this behavior by clearing the current data and adding it back, with the new value included. I know this would not be a very optimal way, but it helps you get to your needed behavior.

Edit: I added an add(index, x, y) method in XYSeries. You can download a version including this feature here.

Upvotes: 1

Related Questions