Center domain label Androidplot bar chart - android

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);

Related

Android MP Chart library get X-axis height

Let's say I have an Activity containing a ChartView (blue rectangle)
Now, I want to place another View on top of it that will stretch from the X-axis all the way to the top of ChartView.
I tried to do that by setting the margin-bottom equal to the height of the X-axis (red area), but I don't know how to get its height
How can I achieve this effect? Is there a way to get X-axis height in Android MP Chart? Or maybe there is a walkaround that will have a similar result?
Desirable outcome (the gray area is a view placed on top of the chart):
chart.getXAxis().mLabelHeight returns the height of x-Axis by pixel.
You can get it after OnGlobalLayoutListener, because it is calculated after x-Axis is drawn.
----------Updated Jun 22nd
another way is to use "getHeight() - mViewPortHandler.contentBottom()", but mViewPortHandler is protected, so an extended chart is necessary to provide access to mViewPortHandler

Androidplot align title of the plot at the right corner

Which property is using to set the title of the plot at the right corner. Right now the title is showing in the middle.
I need the Lead II is displayed at the right corner of the plot.
This should do the trick:
plot.getTitleWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0,
YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.RIGHT_TOP);
In future release (most likely 1.0) you'll also be able to do this via XML attrs.

achartengine; fitting all x axis labels without clipping, and without margins on graph

I'm using a fill to color the area below my chart, and I want the graph to take up the entire view, so I'm setting zero margin on the right and left in my renderer.
mRenderer.setMargins(new int[]{20, 0, 20, 0});
Graph renders great; uses all horizontal space and doesn't look wonky like it does without fill extending to right or left margins when they're set to > 0 values.
I'm also using custom text labels, aligned center, and I'm getting the outer two labels clipped; setting padding on x labels amplifies the problem by pushing labels off view.
Is there a way I can fit all the x labels in without the truncation, and without having to use margins? I can fit them all using margins, but then it just looks funky using the fill below.
Ideally, I guess there'd be some way to set alignment on each text label individually; probably asking for a lot. Or, a means to specify whether it should fit x labels when using custom text labels, such that it would align right on the first, and align left on the last.
Thanks

How to show grid for a custom x axis label: achartengine

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.

Android - How can align the labels' text with their axis?

I'm using achartengine. I don't know how to align the labels' text with their axis. On some screens, the text is centered with the axis; on other screens, they're on the bottom or on the top of the axis.
Is there a way to globally put them in the center of the axis?
I think you can use the following:
mRenderer.setYLabelsAlign(Align.LEFT, 0)
If you want to set the alignment on the right side of the grid, just set Align.LEFT, which means they are align on the left.
Reading these two threads might clear it more: Android AChartEngine - Unable to change textColor of Y-Axis Labels and AChartEngine : Align Y-Axis Labels on right side of Axis itself
Hope it helps.

Categories

Resources