MPAndroidChart, how to center XLabels above grid-lines? - android

I have a simple linechart with MPAndroidChart library:
chart.setDrawYValues(false);
chart.setDescription("");
chart.setDrawVerticalGrid(true);
chart.setDrawGridBackground(false);
XLabels xl = holder.chart.getXLabels();
xl.setCenterXLabelText(true);
xl.setPosition(XLabelPosition.BOTTOM);
YLabels yl = holder.chart.getYLabels();
yl.setLabelCount(5);
// set data
chart.setData((LineData) mChartData);
chart.setDrawYValues(true);
chart.setValueTextSize(20f);
// zooming on both axis
chart.setPinchZoom(true);
chart.animateX(1000);
But I have a visualization problem. Labels on the X axis aren't under the relative grid line, but between the two lines (on Y axis I don't have this problem). Is there a way to put Y labels exactly under the relative grid line?

Calling this:
XLabels xl = chart.getXLabels();
xl.setCenterXLabelText(true);
will cause the labels to be drawn between the lines. If you call setCenterXLabelText(false); the labels should be exactly above the individual grid-lines.
Also check the example project LineChart. There the labels are exactly above the lines.
Update
There is no getXLabels method in version 3.1.0. Use this:
chart.xAxis.setCenterAxisLabels(true)

Related

MPAndroidChart - how to draw grid line for only max and min value in y axis(left axis)?

I use MPAndroidChart to check the graph of the polonomial equation.
I want to get the maximum and minimum values ​​in the graph obtained, but grid line of y axis(left axis) like this.Current Chart
Unlike the above figure, I would like to draw the y grid line of the graph as follows.The chart I want to get
Is there any way to display grid line of max and min value?
I tried to solve it using the setValueFormatter function, but I do not know how to approach it.
https://weeklycoding.com/mpandroidchart-documentation/axis-general/
You can use setShowOnlyMinMax(boolean enabled)
That is used to showing min / max label

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

How to set the range X axis and Y axis in William chart android

I am embedding a line chart view in android . The plot is drawn over a dataset of three months of stock of an IPO . The chart is drawn nicely but the values on X axis and Y axis gets very clumsy. Is there a way i can set the range of X axis and Y axis . Am using William Chart library to draw the chart.
You can use this to set scale your chart
chartView.setAxisBorderValues(newMin, newMax, step);
Source: https://stackoverflow.com/a/30688437/1853912

How to plot chart in GraphView with no background?

How to make graphview background completely blank, not even show x axis and y axis.
couldn't find anything on web
I got my solution by adding these lines
mygraphview.getGridLabelRenderer().setGridStyle(GridLabelRenderer.GridStyle.NONE);// It will remove the background grids
mygraphview.getGridLabelRenderer().setHorizontalLabelsVisible(false);// remove horizontal x labels and line
mygraphview.getGridLabelRenderer().setVerticalLabelsVisible(false);
// remove vertical labels and lines

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

Categories

Resources