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
Related
Is there a way to programmatically change the YAxis Range of a chart in MPAndroidChart?
For instance, given the YAxis displays 0,10, I want to programmatically set the YAxis to -5,+5, but I want to do this several times during the course of an application.
From the documentation, I think you should give a try with a combination of :
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.
moveViewToY(float yValue, AxisDependency axis): Centers the viewport to the specified y-value on the provided y-axis (left or right).
Code for your example:
yourChart.setVisibleYRangeMaximum(10, YAxis.AxisDependency.LEFT);
yourChart.moveViewToY(0, YAxis.AxisDependency.LEFT);
yourChart.invalidate();
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);
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);
Is there any way to limit the scroll area of AChartEngine? I have a graph of stats for a team where the X-axis represents time and the Y-axis represents score and it doesn't make sense to have negative for either. I'd like to make it so that the farthest that the user can scroll down and to the left would put the origin in the bottom left corner of the screen. I appreciate any assistance.
Try using setPanLimits() method ..
double[] panLimits={0,10,0,50}; // [panMinimumX, panMaximumX, panMinimumY, panMaximumY]
mRenderer2.setPanLimits(panLimits);
where mRenderer2 is XYMultipleSeriesRenderer .
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.