I using the 2.0.8 release of MPAndroidChart
I have a problem when the y-values are all zero, and the bars are not shown in the BarChart.
I checked the sample project:
Unchanged code:
Just changing for all values of y are zero in the line 260, with
yVals1.add(new BarEntry(0, i));
but this happens:
And the same happens in my project, when some bars have nonzero values, all bars are displayed, like this:
but when all the bars are zero, no bars are shown and only one label is shown on the x-axis
How to fix this?
I need the chart display all values even the values of 'y' are all zero.
i was getting the same kind of problem as you.
i have a bar chart, when all the y values are 0, the bar won't show at all.
but if there is at least one y value that isn't 0, the bar will showed up even the rest of the y values is 0.
so i think this is a bug from MPAndroidChart.
but i found a way to tweak it a little bit.
you need to set the fixed max axis value, when all the y values are 0.
here is the code to set the fixed max axis value :
leftAxis.setAxisMaxValue(100f);
by doing that, when all the y values are 0, you will set max axis value to 100, but you can set it to other value as long as the max axis value is not 0, and the bar chart will shown even if all the y values are 0.
hope it will fix your problem
Related
I am using MPAndroidChart to show a bargraph in my Android application. My Y axis values range is in between 0 and 30. I need to show Y axis labels from 0 to 5 always on viewport if Y axis values below 5. If exceeds 5, auto adjust the labels and show as usual. Any way to achieve this.
I am using MPAndroidChart and I have a CombinedChart with several lines and one bar, and even my lines started to draw in negative numbers, the bar always start in zero.
How can I draw the barChart according the begin of the chart?
The bar cannot cover the area below zero because that just would not be correct behaviour of a barchart.
If you add an entry with value 30 on the y-axis, it should cover exactly a range of 30 on the y-axis, and not 30 + whatever space is left to the bottom. That is simply not correct.
In case you still want to have the bars to fill the whole screen, you can "cheat" and use stacked bars with 2 values. The first value represents the "starting point" of the bar, and the second value the actual value.
// e.g. -100 starting point, 30 actual value
// covered area is -100 to 30 on the y-axis
BarEntry stackedEntry = new BarEntry(new float[] {-100, 30}, xIndex);
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'm trying to make a line chart using MPAndroidChart that has a Y Axis with a min value of 0 and a max of 255, but I haven't been able to get the max value to show up when viewing the chart. It always shows the top value as something like 240 or 250. I've tried a couple variations of setting the label count but that hasn't helped either. Here is what I'm doing right now.
YAxis yAxis = lineChart.getAxisLeft();
yAxis.setAxisMaxValue(255);
yAxis.setAxisMinValue(0);
yAxis.setLabelCount(5);
I'm setting these before I add the data to the chart.
I am using achartengine 1.0 and I am trying to set the gridlines for my LineChart.
The Y-axis has a min value of 1 and a max value of 7. I need the chart to display every step in this interval, so I added a label for 1, 2,3,... with
addYTextLabel();
Now I would like to display a gridline for every value on the Y-axis.
But when I add the grid for this axis, there are only 3 lins, at 2, 4 and 6.
How can I get the grid to show a line for all values?
best regards,
htz
with setYLabels() you can set the number of displayed labels for the Y axis. With a displayed label, there comes a gridline.