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.
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
}
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."
Just need some help. I am currently making an application for our project. My application get the user input which is number because it gets the quantity of the object. My problem is how i will make object to put on it's desired coordinates. Example chair and i enter quantity of 2 then if you click the button you will be directed to next page then you will see the 2 chairs. thats the interface of application when the user use it. but we need to put coordinates to the chair so that it likes generating object and arrange them to our desired coordinates.
Thanks Guys. :)
Do you actually need to calculate screen coordinates yourself? It would probably be easiest to build a LinearLayout and then add items to it in a loop.
See the first answer here for details on how you can do that: Android: Add a textview to linear layout programmatically
You could do the same with a RelativeLayout if you need more complicated positioning, or an AbsoluteLayout if you want total control over positioning. I would be hesitant to use those unless you have a need that's not met with the LinearLayout.
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 am trying to create a candy crush like game. Correct me if I'm wrong, but the way I see the basic logic of candy crush, several rows and columns were created and objects (e.g. candies) are placed on each box, forming a pattern will erase previous objects and will be replaced by a new one. My question is, shall I use a grid or table layout? Shall I create an array for objects (e.g. food, crackers) where it will be placed? are buttons in android shall be used to swap it with different objects?
Thanks for the help. Android newbie here. :)
Definitely check out the official docs for your use-case.
GridLayout: http://developer.android.com/reference/android/widget/GridLayout.html
TableLayout: http://developer.android.com/reference/android/widget/TableLayout.html
I'm not familiar with the candy crush game but from your description I would use a Table Layout as it looks like every item you'll have will stay in its' assigned cell. GridLayouts are very helpful if you have Views that extend past their cell boundaries. Just in case you should decide to use a GridLayout here's a wonderful article on them: http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html
"Shall I create an array for objects (e.g. food, crackers) where it will be placed?" - That sounds like a fine thing to do to me!
"are buttons in android shall be used to swap it with different objects?" - Buttons are simply a type of View, replacing a Button with some other View inside a TableLayout should be pretty straight forward.
I know this was asked forever ago but maybe this could help someone? GL!