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.
Related
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
}
Wanna implement the filling of my ListView with the effect like that: the first item rotates X and fades in, later the second one and so on.
One way to do it is clear - add items one by one to the adapter (just like in that post), while the animations are handled by LayoutTransition object, which I set in advance.
However, I have a strange feeling, like it'd be somewhat a crutch to add items asycnchoniously just in sake of animation effect. Does anybody know how to do it better?
UPD:
Some details: I want items to be animated only when the underlying data changes, for instance, the server sends new info and the list updates, just like the old departure boards in airports.
Use a LayoutAnimationController....
LayoutAnimationController lac = new LayoutAnimationController(AnimationUtils.loadAnimation(getActivity(), R.anim.table_row_appear), 0.5f); //0.5f == time between appearance of listview items.
listView.setLayoutAnimation(lac);
Whenever you want to run the animation :
listView.startLayoutAnimation();
Finally, I ended up with using the LinearLayout instead of ListView because of the view reusage, that reruns the animation for every view whenever it's showed up again.
But I did it just because I didn't have too many items to show. Another approach, as I guess, is to load animations in adapter, compute delay in accordance with item position and to store the map with the info, wether the view has already been animated in or not.
You can create an animation(transition + fade or any other effect you want) and add the animation to the Layout (view) that you return in "getView"
the animation shall take in consideration the "position" parameter to create the delay when the animation is started.
enjoy
daniel
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."
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
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.