I want a functionality where if user clicks on the the graph and if the x co ordinate is close to our point on XY line graph then I want to show a vertical grid for that point.
The only function that seems related is
mRenderer.setShowCustomTextGridY(boolean showGrid)
But for which value should the grid be shown is not clear in the documentation.
Please help. Which function should I use?
You need to use:
renderer.setShowCustomTextGrid(true);
Once you have the X axis value, you can add a custom text label this way:
renderer.addXTextLabel(x, "label");
Then, if you call a mChartView.repaint(), the custom text grid will be displayed.
Related
I have 3 issue related to MPChartAndroid.
How to make chart to see selected values.
1. Add space to the left of LeftAxis and to the right of rightAxis to fully see the values.
2. how to make first and last chart value to fully see the values.
3. Add space under xAxis to see the cut text.
To overcome issue with cutoff x-Axis label, you need to set some extra space on bottom of your chart view.
mLineChart.setExtraOffsets(left,top,right,bottom); try code below
mLineChart.setExtraOffsets(0,0,0,10);
For overcome issue with overlapping value on axis line you need to set some spacing (start position of lines) on x-Axis, try code below
xAxis.setSpaceMax(0.01f);
xAxis.setSpaceMin(0.01f);
also try xAxis.setAvoidFirstLastClipping(true);
I would like to add some extra labels to a LineChart (MPAndroidChart) like in the image below. Notice the "Advanced", "Novice" etc labels.
How could I add those to specified y-axis positions so they will always show up like y-axis labels but perhaps on the inside of the graph as shown - or on the right side if necessary?
Update:
All I needed to get what I needed was some LimitLines like this:
LimitLine noviceline = new LimitLine( SSGlobals.getWeightinPreferredUnits_fromPounds(standardweightsarr[2]) , getString(R.string.novice));
noviceline.setLineColor(ContextCompat.getColor(getActivity(), R.color.accentline));
noviceline.setTextColor(ContextCompat.getColor(getActivity(), R.color.accentline));
noviceline.setTextSize(12);
noviceline.setLineWidth(4);
I might style it up a bit more but so far the result looks like so:
There are a couple of options here.
You can see if the LimitLines will fit your purpose - they are able to be configured with a label like this:
LimitLine llXAxis = new LimitLine(10f, "Index 10");
llXAxis.setLineWidth(4f);
llXAxis.enableDashedLine(10f, 10f, 0f);
llXAxis.setLabelPosition(LimitLabelPosition.RIGHT_BOTTOM);
llXAxis.setTextSize(10f);
xAxis.addLimitLine(llXAxis);
You could also use a FrameLayout with over the chart with TextViews for the extra info you want to add. See this
question for something similar and also this question for how to convert between chart values and on-screen pixel co-ordinates.
Alternatively, you can extend the renderer itself to draw your custom text. Please see How do MPAndroidChart renderers work and how do I write a custom renderer? if you wish to attempt that.
I just want to show only X Y axes and labels on these axes and don't want to show grid lines in Android GraphView. How can I do that?
Thanks in advance.
I believe the following call should do the trick :
your_graph.getGridLabelRenderer().setGridStyle( GridLabelRenderer.GridStyle.NONE );
Please do note I haven't tested the above call :)
If you use this all the grid lines will be Removed
your_graph.getGridLabelRenderer().setGridStyle( GridLabelRenderer.GridStyle.NONE );
For Setting Horizontal Line visible
your_graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.HORIZONTAL);
For Vertical Line visible
your_graph.getGridLabelRenderer().setGridStyle( GridLabelRenderer.GridStyle.VERTICAL);
The following code will remove the grid and then show the X and Y axis
graph.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.NONE);
graph.getViewport().setDrawBorder(true);
Currently the domain label is positioned below the Y axis labels. Is there a way to set the domain label to appear in the middle of the X axis?
Using the below image as an example I want the domain label (Time secs) to appear where the legend (Thread #1) appears. (legend will not be visible).
(source: androidplot.com)
To center the domain label I used the below.
plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0, YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);
Take a look at the "LayoutManager" section of the "Plot Composition" doc. It gives a pretty good summary of how to position the visual elements (referenced as widgets in the doc) of a plot. In your case you'll be invoking plot.getDomainTitle().position(...).
This worked for me with v1.5.4:
plot.getDomainTitle().getPositionMetrics().setXPositionMetric(new HorizontalPosition(0, HorizontalPositioning.ABSOLUTE_FROM_CENTER));
It sets the horizontal position to the center without modifying the vertical position.
It may also be useful to set the text alignment to CENTER:
plot.getDomainTitle().getLabelPaint().setTextAlign(Paint.Align.CENTER);
I have a multi-line EditText/TextView, say 1000 line.
The contents can't be shown on one page, actually there will automatically be a vertical scroll bar.
I want to make a button that can jump to line 500, and the result view start from exactly at line 500.
Anybody know how to achieve this?
You should be able to calculate the scroll in the Y direction using TextView.getLineHeight(), TextView.getLineCount() and TextView.getHeight().From there you can call TextView.scrollTo(0, calculatedY).I'm assuming you always want to have the left side of the view visible. Of course, if your lines were longer than the current View could display, you could similarly calculate an X scroll position also.