I am using Achart Engine Line chart to display values, i am using point style CIRCLE.
I am trying to implementing the below :
1) Increase the point style width - i mean the circle should be bit bigger.
2) On click of each point i want a popup to be displayed on top of that which will display the values of X and Y.
I have done some research on this but was not able to find the solution.
I found this code but how to display the small popup with values ?
final LineChart chart = new LineChart(buildDataset(mTitles, data), mRenderer);
final GraphicalView view = new GraphicalView(mContext, chart);
view.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
double[] xy = chart.toScreenPoint(view.toRealPoint(0));
int[] location = new int[] {(int) xy[0], (int) xy[1]};
SeriesSelection seriesSelection = view.getCurrentSeriesAndPoint();
if (seriesSelection != null) {
final Data d = mModel.getDiaryAt(seriesSelection.getSeriesIndex(),
seriesSelection.getPointIndex());
//show popup at xy[0] xy[1]
}
}
});
It might have been not given in the SDK but still if anyone has tried this as was successful.
** EDIT **
Link 1 : achartengine toScreenPoint(double) always returns nullPointerException
In the image you can see a popup i want to implement like that.
You can see an example here on how to display the clicked point in your chart, using AChartEngine.
Related
I want to achieve an effect similar to this using the MPAndroidChart library
I want my label to be attached to the Chart line or at least be close to it. Is something like this possible using this library? Or is there a walkaround for this? Something that will have a similar result
A possible way is to use the marker, chart.setMarker(), but marker only shows when user tap on the chart, if you want the marker to show constantly, an custom chart can be invoked and override the function drawMarkers like this, the marker is drawn in the middle of chart:
#Override protected void drawMarkers(Canvas canvas) {
int j = 0;
IDataSet set = mData.getDataSetByIndex(j);
int i = set.getEntryCount() / 3;
Entry e = set.getEntryForIndex(i);
Highlight highlight = new Highlight(e.getX(), e.getY(), i);
highlight.setDataIndex(j);
// callbacks to update the content
mMarker.refreshContent(e, highlight);
MPPointD pix = getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY());
highlight.setDraw((float)pix.x, (float)pix.y);
// draw the marker
float[] pos = getMarkerPosition(highlight);
mMarker.draw(canvas, pos[0], pos[1]);
}
Picture as below, the yellow tag is the marker, it is displayed constantly and without a user tap:
----Updated July 5th
In the demo LineChartActivity1(https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java), line 98, chart.setMarker(mv); sets the Marker, and it allocated by new an MyMarkerView. The drawMarkers can be added at https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartLib/src/main/java/com/github/mikephil/charting/charts/LineChart.java, but it's better to use a customed Chart extends from LineChart
I'm developing a kids alphabets learning application. I need to get the X and Y coordinates of the whole text area from a textview to allow them to draw over the text only. For Example: I have a letter A in my text view, I need to allow the user to draw the letter only over the A text only and need to block the drawing outside the text.
My only problem is I don't know how to find the text area for alphabets as I have increased the font size for the text to display bigger and center aligned it in the screen.
Any suggestions will be really helpful.
Something like this (https://www.youtube.com/watch?v=15B3L78jWfI)?
To stop user from drawing outside of the given area, overriding (12:22) onTouchEvent() you could just put a clause checking whether the given coordinates are inside, or not.
To check if they are inside, you could write such a simple function:
int MIN_X;
int MAX_X;
int MIN_Y;
int MAX_Y;
boolean isInside(int xCord, int yCord){
if(xCord>=MIN_X && xCord<=MAX_X && yCord>=MIN_Y && yCord<=MAX_Y)
return true;
return false;
}
You'd only have to override the min and max values, each time the chosen area changes.
Try the below mentioned code:
ViewTreeObserver vto = textView.getViewTreeObserver();
vto.addOnGlobalLayoutListener (new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
textView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
// Initialize a new integer array two hold the TextView x y position
int[] location = new int[2];
textView.getLocationOnScreen(location);
}
});
I set 2 values on piechart. I want to animate it. But I want to change animation way. All animations do right to left angle. I want to do left to right angle. How can I change animation direction?
Edit 1: Library: MPAndroidChart
Edit 2: Althought it is not very relevant, I add following code here.
mButton_AvailableLimit.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
// fromAngle and toAngle is a float variables that less then 360
mPieChart.spin( 500,fromAngle,360 - toAngle, Easing.EasingOption.EaseInOutQuad );
}
} );
It's very simple in fact,
//for rotating anti-clockwise
mPieChart.spin( 500,0,-360f, Easing.EasingOption.EaseInOutQuad);
pieChart.animateX(1000); this is work fine
I am trying to animate a pointer around the screen in an android application.
I am using an imageview as the pointer inside a relative layout as follows:
final RelativeLayout container = (RelativeLayout) findViewById(R.id.container);
pointer = (ImageView) findViewById(R.id.pointer);
pointer.animate().setDuration(2000);
I then want to move the pointer up 10 pixels every time I click a button:
// ONCLICK LISTENER FOR LEFT BUTTON
btnUp.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//get positon of pointer
leftPoint = pointer.getLeft();
topPoint = pointer.getTop();
int xValue = container.getWidth() - pointer.getWidth();
int yValue = container.getHeight() - pointer.getHeight();
pointer.animate().x(leftPoint).y(topPoint-10);
}
});
This works the first time I click the button but will not move it any subsequent times. I have tried making the int points static but this did not help.
Any help greatly appreciated.
This might sound counter-intuitive, but animating a view doesn't change its location. Your code is demonstrating it. When you do this line:
topPoint = pointer.getTop();
You get the same value every time.
You need to change pointer's position at the end of the animation.
This answer shows how someone else has done it.
Other Considerations
You could use object animator, if you are only targeting SDK 11 and above. Here is a little intro to it.
If you want to interrupt your animation, you can check its status, and find out its current y offset. You can add that to the position of the view before starting the animation. Here is an example.
I am new to android and i want to fix a pop up dialogue box relative to another button. I am inflating the popup window using code. How can i get current position of the button so that i can use these values for inflating the pop up window.
This is the code I use to get the current x/y coordinate of any View Object:
/**
* #return the absolute x and y coordinates of the given view
*/
public Point currentPosition(View view)
{
int[] loc = new int[2];
view.getLocationOnScreen(loc);
return new Point(loc[0], loc[1]);
}