MPAndroidChart - how to draw a circle in the last entry only? - android

Using MPAndroidChart, Is there a way to draw only one circle in line chart?, this means that only the end of the line will be represented be a circle as shown in this image:
#PhilJay

I have searched and struggled a bit because of this and in my opinion the best solution is to use setIcon which is quite a recent method and won't get messed in case you have an animation. Here is an example:
dataSet.getEntryForIndex(position).setIcon(ContextCompat.getDrawable(this,R.drawable.myDrawable));
This will work for any position, in case you wish to have different points with different drawables

Well a workaround could be that you always put the last entry in a separate DataSet as well which has setDrawCircles(...) enabled. So you add the last entry to a separate DataSet and to you actual DataSet as well.
As soon as there is a "new" last entry, clear the circle-dataset and add that new entry to it.
Pseudo example
public void add(Entry e) {
actualDataSet.addEntry(e);
circleDataSet.clear();
circleDataSet.addEntry(e);
chart.notifyDataSetChanged(); // let the chart know it's data changed
chart.invalidate(); // redraw
}

Related

android graph view not shown when the data is the same

I'm using android graph view from here it works fine , but when the Y value of data are the same it doesn't show any thing more like the whole View visibility is GONE.
I can handle this by appending a fake value to the data point but it doesn't look fine.does anybody have an idea. Thanks a lot!
this part of my code
/...
DataPoint[] dataPoints = new DataPoint[length];
// populate my dataPoints
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(
dataPoints);
graph.removeAllSeries();
graph.addSeries(series);
// make other stuff
/...
You don't need to append a fake value.
In this case like what you have mentioned (same value for Y) actually it works correctly, the line will be created but it coincides on the X-axis actually as the Y-axis is starting from the Y value you have set, not zero. Changing the line colour by adding following lines to your code, you will be able to see the drawn line.
graph.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_bright));
series.setColor(Color.GREEN);
graph.getViewport().setScalable(true);
graph.getViewport().setScrollable(true);
I'm using GraphView as well, and seem to be having the same problem. That the graph doesn't have the right data when I come back to the same fragment. I don't know if you are using fragment or not, but if you do then you need to pop that fragment that contains the graph. So when you came back to the fragment, you will create new fragment instead of taking the fragment from the stack. This works for me. Don't know how accurate is this, cause I'm new to Android dev, but it works for me. Hope this helps.

How to redraw correctly bargraphview using the graph view library for Android?

For some reason (that I can develop if you want/need) I have to redraw all the chart periodically. So, I use removeAllSeries then addSeries, plus removeAllViews then addView. It works but the problem is that addView adds the view not by simply refreshing all pixels of the tablet but with a sort of "animation" that puts firstly the View a little bit (2 or 3 pixels) shifted to the right and then it takes the right place. The consequence is that, everytime I redraw my graph, it looks as if there is a "vibration" (it's not fluid).
Do anyone have some issue? Could this undesired "animation" be related to how the addView method is done?
there are three ways:
redrawAll() method. Maybe it is protected, but you can overwrite and
make it public
change the data in series (appendData or resetData). The Graph will
automatically rerender.
removeAllSeries + add new series. No need to call
removeAllViews/addView. Take a look at the GraphViews-Demos project,
there is an example about that.
Cheers
Thank you for your answer ! I actually just simply overrided the ValueDependentColor() method directly in my main activity. The color depends on a timer. So, when I reset data after x seconds the graph rerenders as you said in your "2."

Calculating distance between starting point to destination using Google maps V2 in android

I have one starting point and various stops, so I want to calculate the distance between them. I used this referencePlease check
After calculating distance and duration I want to bind that data in list using list adapter. At last am able to calculate all the distances and duration but failed to bind the data in list. Am getting Null pointer exception in my listview adapter because list generates before I got response from api.
Any help will be Appreciated!! Thanks
Well, since you've not posted any code, I'll give you a slightly generic answer that could help you.
Put a try catch around the initial assignment to the listview, so as to avoid it from causing the app to crash.
Then, after you've managed to calculate all the distances you desire, tell the list adapter that the data set has changed by using:
adapter.notifyDataSetChanged();
Make sure its after your dataset to fill the list with has been acquired.
This will cause the list to "refresh" itself, thereby making it visible in the listview.

Line chart for Android with adapter

I need a line chart that will use adapter like in ListView.
All charts what I saw require array of points as input data. But I have database that contains a lot of points. For drawing this data I should convert selected cursor to an array. It's not suits me. Because in one moment of time on the screen can be displayed scanty part of data. Other points should be displayed only when I do scroll.
Pictures for understanding.
This is what I want:
What hapened when I scroll:
New points should be created only when it's needed.
Hi i don't know whether this solution meet your requirement,But you can try HoloGraphLibrary
Which contain all types of graph including line graph
Wish it will help you,Thank you

Java-Android / How to dynamically add plots to an AchartEngine chart

I have 2 Fragments, one with my chart and below one with a TableLayout with my TimeChart values. I would like to add to my chart, a function when i click (or hover) one value of my table, a plot draw himself on the chart at specific date and value but i didn't find yet a way to do this. Could some have already done something like that?
Thanks in advance
You can definitely do this. One option would be that you add an extra series that would contain only the extra point you want to render. When you want to render it at another location, just remove the previous one and add another one. Don't forget to call chartView.repaint(); after every such change.

Categories

Resources