Android achartengine text label margin and padding - android

Hi developers, I have a question: how can I make the gap between labels and bars smaller, I've tried setting the margin of XYMultipleSeriesRenderer to a different range(both positive and negative), but that doesn't affect the gap between labels and bars. And also passing negative value into renderer.setXLabelPadding() seems to be ignored - the text labels are on the X axis since the graph is rotated 90%
I am using achartengine 1.1.0, which should be the latest.
Here's a section of the code that I used to manipulate the apperance:
renderer.setOrientation(Orientation.VERTICAL); //horizontal bar-graph
renderer.clearXTextLabels();
renderer.setYLabels(0); //remove units on the Y axis(the horizontal axis since the graph has been rotated 90 degree)
renderer.setXLabels(0); //removes 'values' from the X-Axis
renderer.setMargins(new int[]{10, 0, 90, 0}); //top, left, bottom, right. Since its a horizontal bar graph, the margins has been rotated clock-wise. setting them to negative doesn't solve my problem.
renderer.addXTextLabel(0.9, "Average");
renderer.addXTextLabel(1.2, "Maximum");
renderer.setXLabelsPadding(-200f); //no effect
renderer.setYLabelsPadding(-200f); //no effect

try render.setBarSpacing(float); for spacing between bars. I used this and it worked.

Related

MPAndroidChart: How to create dual axis?

I am using MPAndroidChart for drawing line chart.
I need to draw a Dual YAxis Line chart (i.e. with 2 Y Axis, one on left and other on right). But when I draw the graph it is being drawn from left. It takes into consideration the Left YAxis values rather than the Right YAxis values.
I am drawing Weights(kg) on right side and Heights(ft) on the left side.
As weights will be in terms of 40s, 50s etc and heights in terms of 5, 6 etc... The Line being drawn for Height takes left reference, which has 50s, 60s and hence never comes up.
Please let me know how to direct to draw considering the right Y Axis for Height rather than left Y Axis.
You can just use the setAxisDependency function in order to let a DataSet depend on a given axis. In your case it should be set to right:
LineDataSet set = new LineDataSet(data, "Your Label");
set.setAxisDependency(YAxis.AxisDependency.RIGHT); // plot this set against the right axis

MPAndroid candlestick combined with volume bar chart height issue

I need suggestion on how to limit the MpAndroid CandleStick chart combined with volume bar chart at the bottom so that volume bar max height can be limit to below 1/3 of chart area Yaxis . From the chart attached , this is somewhere Y Max at 3million region viewport in the left Axis. The current combined chart is ruin by the volume bar chart.
Thanks
setVisibleXRangeMaximum(float maxXRange): Sets the size of the area (range on the x-axis) that should be maximum visible at once. If this is e.g. set to 10, no more than 10 values on the x-axis can be viewed at once without scrolling.
setVisibleXRangeMinimum(float minXRange): Sets the size of the area (range on the x-axis) that should be minimum visible at once. If this is e.g. set to 10, it is not possible to zoom in further than 10 values on the x-axis.
setVisibleYRangeMaximum(float maxYRange, AxisDependency axis): Sets the size of the area (range on the y-axis) that should be maximum visible at once. You also need to provide the axis this constraint should apply to.
For more info Refer this
Thanks for your comment ,I do not think setting XrangeMax or Min will help , it only limit the x-axis down to certain visible display range instead of showing the full range of the dataset points . The chart shown above has about more than 4000 data points , I have narrowed the visible x-range using set chart.setVisibleXRangeMaximum(100) and also chart.moveViewToX(3000) to optimise performance. What I need is some functional procedure to set the max Y-axis (eg left Y-axis) at certain specific offset position , so that the lower portion of the chart could be restricted to the volume bar chart by clipping the specific rectangle viewports. I am not sure if that is possible , narrowing the YVsibleYrange is not what I have in mind. What I would like to have is
That is possible. All you need to do is plot the data against two different axes (as you are already doing), and then set the top space for each axis separately.
Customizing the axis range
setAxisMaxValue(float max): Set a custom maximum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
setAxisMinValue(float min): Set a custom minimum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
setSpaceTop(float percent): Sets the top spacing (in percent of the total axis-range) of the highest value in the chart in comparison to the highest value on the axis.
setSpaceBottom(float percent): Sets the bottom spacing (in percent of the total axis-range) of the lowest value in the chart in comparison to the lowest value on the axis.
More information in the documentation.
To workaround , I have coded the Y axis to be at 1/x1 of Y viewport height to mark the volume bar top at YMAX in the multiple of x1 where x1 variable can be ={3, 4 or 5} float ymax=barDataSet.getYMax(); float ymaxd=(float)Math.floor (ymax*x1); leftAxis.setLabelCount(x1,false); leftAxis.setAxisMaxValue(ymaxd);

How to Increase X or Y axis label sizes in AChartEngine in Android and Enable zoom

I have the whole line chart working. However the fonts are really small for the labels in x axis and y axis and also on the points where it is plotted. I've circled them in the picture in order to let you know what labels I am talking about.
Also I have disabled the zoom buttons, however we can still zoom using our fingers on the screen. When I zoom in the chart gets messed up. How do I not allow any kind of zooming?
You can set labels size in pixels for 2 axis together
renderer.setLabelsTextSize(float textSize)
Also you can set label color, align gor X and Y axis, for example:
renderer.setXLabelsColor(Color color);
renderer.setYLabelsAlign(Paint.Align.RIGHT);

AChartEngine : Align Y-Axis Labels on right side of Axis itself

i am using aChartEngine for android. i have a problem with the y-axis, when the values reaches 10000 or more, the left digit is disappeared (Check the photo) in the photo the values are 7000-11500 but the values appearing above 10000 are 0000,0500, . . . etc
I would like to set the y-axis labels on the right side of the axis or something like that
can anyone help ?
knowing that i used
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setYLabelsAngle(angle)
To view the Y axis date if the margins are fixed, so that the data will be displayed in tilted format,in which more characters will be seen.
Else the margins spacing have to be set for viewing the y axis labels.
You can tweak the margins of your chart:
renderer.setMargins(margins);
where margins is an array of [top, left, bottom, right]
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.
multiRenderer.setYLabelsAlign(Paint.Align.RIGHT);
multiRenderer.setMargins(new int[]{0, 100, 0, 0});
multiRenderer.setYLabelsPadding(20);
Use Above code to align Y axis right with padding.

Android AChartEngine - Unable to change textColor of Y-Axis Labels

While using AChartEngine (JAR 1.0.0) for Android, I see a method that allows me to change the color of text for X-Axis (mRenderer.setXLabelsColor(Color.BLACK))
Unfortunately I am unable to find a corresponding method for the Y-Axis labels!
Also is there a way to set the color of the actual line graph?
I also tried to align the labels to the left of Y-Axis using
mRenderer.setYAxisAlign(Align.LEFT, 0);
mRenderer.setYLabelsAlign(Align.LEFT, 0);
but it does seem to function.
There is renderer.setYLabelsColor(); for setting the Y axis label color.
When you use Align.LEFT, it means they are left aligned, if you want to right align them on the left side of the axis, use Align.RIGHT.
The line graph color is the one from its own renderer.
To align and set a color properlly you need put it as follow:
mRenderer.setYAxisAlign(Align.LEFT, 0);
mRenderer.setYLabelsAlign(Align.RIGHT, 0);
// setYLabelsColor method you need include which the
// int for your YLabel, since this library you can
// use more than one YLabel, so in your case,
// you only have one YLabel and its index is 0.
mRenderer.setYLabelsColor(0, Color.BLACK);
mRenderer.setXLabelsColor(Color.BLACK);

Categories

Resources