I'm using MPAndroidChart library and can't make labels to have an equal spacing.
When setAvoidFirstLastClipping(false) I get this:
As you can see only label 1 has shifted, others two didn't move a bit.
I also played with getXAxis().setSpaceBetweenLabels(10); The best outcome was:
Related
Thank you for this powerful library.
I have a problem when the values are near to each other and every value has several amount of digits, the value would overlap each others like in the below snapshot.
I tried to make some values upper and some lower the line, or to make values written in vertical way (like x labels in the snapshot), but I didn't find way to do that.
If there is any advice or other workaround, it will be appreciated.
Snapshot is in the link below
Image Shows the problem
I am using MPAndroidChart in one of my projects, i am using horizontal bar charts. Several times if the value of 1 filed it too large the graph kind of shows only that value and rest all other values becomes 0.
Now i understand this is correct behavior since it calculate percentage and divide the values but even in those cases this values should be shown. Is there any way to achieve this ??
Here is what it looks like :
Value of all other fields are pretty small less than 2000 !!
As it is clearly visible in the screenshot you provided, the values are shown. They are just very small (exactly as small as you set them to be) and therefore they are not drawn any bigger on the chart.
I honestly don't know what you expect?
If you want the bars of the small values to be "bigger", then use bigger values.
Something like a logarithmic scale is not yet available for the axes.
In MP Android chart there is no way to handle this issue of 'one-value-is-too-large'. I faced this issue and had to implement a design change. In my chart most values were of range 10 units and only one value was very large around 4000 units. So I decide to not display the large value in chart and display it below the chart. Here is an image view
I am creating a chart using MPAndroidChart with 10 data sets using one of the examples provided. My labels are displaying all on one single line and are not wrapping. They are getting chopped off on the right.
Legend l = mChart.getLegend();
l.setForm(Legend.LegendForm.SQUARE);
l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
I would like to display the labels in multi-lines. Any ideas please?
Currently this library does not support a "wrapping" mechanism for the Legend.
However a workaround could be to set the legend-position to be somewhere right of the chart.
In that way there should be more space for entries when they are aligned vertically instead of horizontally.
This seems like a basic question, but I couldn't find a similar one on SO. While reading the documentation, I was having trouble grasping the concepts. I want to understand what the difference is between top and ascent and also bottom and descent. And where exactly is the baseline? Do you have a diagram to help me visualize it?
Let's first review what the documentation says:
Top - The maximum distance above the baseline for the tallest glyph in the font at a given text size.
Ascent - The recommended distance above the baseline for singled spaced text.
Descent - The recommended distance below the baseline for singled spaced text.
Bottom - The maximum distance below the baseline for the lowest glyph in the font at a given text size.
Leading - The recommended additional space to add between lines of text.
Note that the Baseline is what the first four are measured from. It is line which forms the base that the text sits on, even though some characters (like g, y, j, etc.) might have parts that go below the line. It is comparable to the lines you write on in a lined notebook.
Here is a picture to help visualize these things:
Remember that when drawing on a canvas in Java and Android, going down is an increase in y and going up is a decrease in y. That means that FontMetrics' top and ascent are negative numbers since they are measured from the baseline (while descent and bottom are positive numbers). Thus, to get the distance from top to bottom you would need to do (bottom - top).
The leading is the distance between the bottom of one line and the top of the next line. In the picture above, it is the space between the orange of Line 1 and the purple of Line 2. As #MajorTom noted below, in typography the term is more properly defined as "the distance between the baselines of successive lines of type."* However, Android seems to use the term in the more historical sense. The word (pronounced "ledding") comes from the lead strip that the old typesetters used to put between lines of type. It was basically just a way to adjust the line spacing. In Android I've never actually seen the leading be anything other than 0 and I haven't seen it used for anything in the source code. (Correct me if you know where it is used to calculate anything.) You can change the line spacing in a TextView with setLineSpacing in code or android:lineSpacingExtra and android:lineSpacingMultiplier in xml. These methods, however, do not make use of or modify the leading.
Check out these links for more information:
Precise Android Text Drawing
Font Metrics in Java (and Android)
Layout documentation
Java: FontMetrics ascent incorrect?
FontMetrics not correct when run on android device. Simulator fine
Java Font Metrics (Java doesn't seem to use top and bottom)
Explore more
In order to explore Font Metrics more, I made a simple project.
Rather than listing all the code here. I added the project to GitHub. You can either clone the project, or copy the following files into a new project.
FontMetricsView.java (a custom view)
MainActivity.java
activity_main.xml
Do letters ever go above top or below bottom?
Not usually, but they could. Top and bottom, as I understand them, are set by the font (hence "FontMetrics"), so a font maker could make a glyph go higher than whatever they say the top is (or lower than the bottom). Also, with combining diacritical marks in Unicode it can very easily happen. Here is a rather extreme example (taken from here): M̵̳̙͔̟̱͕̓̀̄̉̅ͧ̋͊͌͑́͌ͪ̒̿̀̚a͔̟̝͔ͥ̈́̏ͮͯ̇͆̊̒ͦͦ͘͢͜y̵̴̢͕̝̩̱͈͕̼̣͕̟̌͗̾ͤ̎͌̄ͣͨ͊ͬb̡̯̰̪̜͙̟̝̠͚̜̥̙̤̃ͨ̋̒̒̊ͧͤ͐̓͋̌̾̇̔̈́̀́͡͠e̵ͯͪ̿̿̂̄ͫ̃҉͏͎̣̹̱̜͉̦̞̪̘̠̝̝͍̼̜̖̥̭͟ ̣̞͙͚̝̰̞̹̗̲̣͙͍͍̀̓͊̂̋ͣ̏̑̍̊͌ͩ͐̎̀ͣͣ̚͟ͅh̛͋̏̍̆ͤ͛͐ͨ̌̋ͤ̎̂ͨ̂̓̑̚̕͟͏̻̣͖̖͚͚͓̲̼̪ȁ̔̅̿͐̑͡͏̝͓̮͚̘̦̰͚͎͔͉͚̮̠̕͜ͅṱ̱̼̖̓̂ͭ̏̅͂ͥ͌ͯ͌͠sͪ̓ͪ̄̌̓ͧ͋͐ͬ̅̑҉̨̪̬͎͍̥̬?̡̮̳͙͓͔̹̘̹͓̘̻̦̣͎̫̐ͤ̐͛́͝ ̧̦̼̘͕̪̠̙͖̦̯̦̘͉͈͕͔̘̻̲͑ͨ̊̈́̐ͫ͐̌ͯ̀͘͝Ḩ̷̸̸̹͉̩̜̹̞ͯ̃̃ͧͬͨ̌̀̾̐̈̇ͧ͛̃͐̀ͦ͞A̴̦̗̬̠͙̭͉̟̺͇̭̰͔͕̯̅̃͋ͪ̈́̉̓̌ͯ̈́͆̋̀ͤ̇̂̿̈́̂͡͡Ṱ̲͎͉̣̳̺̱̜̦̬͕̣͉͇͊̌ͥ͐͒̈́̓́ͥ́́̋͂̅ͬ̆͗ͥ̕͢͡S̍ͧ͗̒͗̂̈ͬ͊̚̚͢͏̗̣̳ͅ!̶̨̡͇͚̙͚̭̱̣̲̳̤̞̫̗̣̦̮̖̞͒͆̿̄͑̃̎͡
Plugging that string into Android we get this:
The diacritical marks go above the top and below the bottom. It is interesting to note that the total width and height are correctly measured by the text bounds, though.
Anyway, for all practical purposes in your programming, you can just assume that the max and min for glyph letters are top and bottom. And usually they will stay within ascent and descent. If for whatever reason you need to know for sure if the letters go beyond top or bottom you can use TextPaint.getTextBounds.
Leading is NOT space between lines in typography. Apparently this is something Android code does not take into account. We've been struggling with this ourselves. The proper definition of leading (from Wikipedia):
In typography, leading /ˈlɛdɪŋ/ refers to the distance between the
baselines of successive lines of type. The term originated in the days
of hand-typesetting, when thin strips of lead were inserted into the
forms to increase the vertical distance between lines of type.
From what I can tell, Android does not have a way to specify this.
I am trying to use a 9-patch as background for a TextView, but it is treated as normal image file. According to the 9-Patch tool and the Intellij IDEA Layout Preview it should stretch properly though.
I am using other 9-patches as well, so the problem can't be due to a misconfiguration of my system (e.g. missing library like in another case).
Checklist of what I've done so far:
made sure the 9-patch perimeter contains only fully transparent or solid black pixels.
file-ending is *.9.png
tried it with and without specifying padding in the image
Here is the image I'd like to use.
Just now I saw the IDE throwing this "information" at me:
"ERROR: 9-patch image ...\res\drawable\timeline.9.png malformed.
Too many rows and columns in 9-patch perimeter."
Are there any restrictions on the 9-patch I am not aware of? Tried searching the documentation for more information about that, but without success.
Thanks in advance,
/me
P.S.: I know the image could be optimized by removing the extra space within the segments, but that's sth. I planned on doing once it is working as expected.
With 2 horizontal markers I was able to use 12 vertical markers (adding one more vertical or horizontal marker will give that error). So I think it counts the intersection (H * V), maximum might be 25 based on other answers.
Update:
Based on android code:
// Make sure the amount of rows and columns will fit in the number of
// colors we can use in the 9-patch format.
if (numRows * numCols > 0x7F) {
errorMsg = "Too many rows and columns in 9-patch perimeter";
goto getout;
}
The maximum value is 0x7F = 127.
A vertical marker is considered as one column, while horizontal marker is one row. so if you have 5 markers in each then it means you have 5 stretchable columns + 6 un-stretchable columns (the areas between the markers) so total of 11 vertical and same for horizontal so 11 * 11 = 121 which is less than 127 so you are good
in my case i had 12 vertical (12+13 =25) and 2 horizontal (2+3 =5) so 25*5=125 still less than 127.
You have to set the text area on your 9-patch. Define it at the bottom and the right of your picture.
Last time I checked:
A maximum of 5 padding markers can be used.
A maximum of 5 scaling markers can be used as well.
(Update: Looks like it might be possible to go above this value. See the additional comment below.)
I have tested in my project, 18 vertical and 6 horizontal markers, returned a warning too many rows and columns. Then I used 18 vertical and 1 horizontal markers, it was good:), I guess it would be no more than 20.
I was hitting the limit too. Building against API 17. I have a grid that has a column for each hour of the day and 4 rows. I played around a bit and I think the constraint is on the number of patch intersections. So if I had just one horizontal patch I made it to around 20 vertical patches before I hit the limit but if I had two horizontal patches I probably only made it to 10 vertical patches. I tried removing the horizontal patch but then you get an error "No marked region found along edge". HOWEVER, if I gave up resizing the height and selected the entire edge as a horizontal patch, I could add all 24 of my vertical patches. I'd guess you'd maybe get to 40 if you left either the entire width or height resizable? Just an educated guess based on the pattern I noticed.