Comments (17)
@aloisdeniel thanks for this great component! I've being used and faced the same problem with label sizes. I`ve created a dependency service to solve that and I hope it helps you, @muhaym, @SteveShepNL and others fans like me :D
PCL
1 - Create an Interface
public interface INativeFont
{
float GetNativeSize(float size);
}
2 - Set chart label size
var dependency = DependencyService.Get<INativeFont>();
chartView.Chart.LabelTextSize = dependency.GetNativeSize(10);
3 - Create dependencies
Android Get Dip equivalent
[assembly: Xamarin.Forms.Dependency(typeof(NativeFont))]
namespace yournamespace.Droid.Dependencies
{
public class NativeFont : INativeFont
{
public float GetNativeSize(float size)
{
var displayMetrics = Android.App.Application.Context.Resources.DisplayMetrics;
return TypedValue.ApplyDimension(ComplexUnitType.Dip, size, displayMetrics);
}
}
}
IOS Get scaled equivalent
[assembly: Xamarin.Forms.Dependency(typeof(NativeFont))]
namespace yournamespace.iOS.Dependencies
{
public class NativeFont : INativeFont
{
public float GetNativeSize(float size)
{
return size * (float)UIScreen.MainScreen.Scale;
}
}
}
from microcharts.
Label font size doesn't seems to be working properly on Android, different version of Android renders in different way.
from microcharts.
That works but then i also need a Padding because the texts are cutted on the bottom :(
from microcharts.
Any update on this? It would be great to get the native font size solution implemented in the library.
from microcharts.
Thanks for the feedback, the text is too small for sure yes. I'll fix it.
For the rotated text, it was like this before but I didn't like it. I could definitively add an option however.
from microcharts.
I forgot, but you should already have access to a LabelFontSize
property available from Chart
instances.
from microcharts.
LabelTextSize doesn't seem to have any effect whatsoever on iOS or Android. On Android I seem to get massive font size and therefore mostly folded under the chart itself, and iOS quite small. This is a fantastic nugget and the only thing keeping my apps from being production quality is not being able to have more control over the label and value label sizing and positioning on the charts. Being able to anchor the chart to the left or right and the labels to the other (or even top or bottom) rather than the chart always in the centre would be nice.
from microcharts.
And also I suggest add rotate labels functional in bar, line charts like in oxyplot. It's needed for fit full text.
from microcharts.
@aloisdeniel The issue with the cut off labels is on PointChart.cs line 124. Where it says canvas.DrawText(text, point.X - (bounds.Width / 2), height - this.Margin + (this.LabelTextSize / 2), paint);
If you change it to canvas.DrawText(text, point.X - (bounds.Width / 2), height - (this.Margin + (this.LabelTextSize / 2)), paint);
it properly positions the labels. It's just a simple issue of order of operations.
from microcharts.
I'm also waiting a solution
from microcharts.
Hey all, working on a new nuget package now. Hope to get something up soon. My current plan is to basically pull the current latest feature branches into master after some simple testing. Will keep you updated if that changes. Should include font size setting ability.
from microcharts.
I'm having trouble here, because I don't have access to a mac to build these projects for ios. So I can only build the uwp, and android projects. So no way to update the nuget and have it available for ios. For the moment, if you need to get some updates, the easiest method is to clone the repo, and build it locally, and include any changes you need for your project, and then just include the appropriate dll's into your project/create your own private nuget so you can share between locations. I'm going to try and get a hold of the original repo owner and see if I can get him to push a new pre-release or something.
from microcharts.
@Nixon-Joseph I may be able to help, I have access to a mac at work. Let me know what branch I can fork and add to...
from microcharts.
@rerickson1 Just had a thought, all of this is just c#, I'm not actually compiling applications. Should be able to just built the proper classes without any issues. Looking into it.
I'm not as incompetent as I seem haha. Just never worked on a published repo before.
from microcharts.
Alright! I think I've successfully created and released a nuget package for both Microcharts, and Microcharts.Forms. Version is 0.8.4-pre. Please let me know if there are any issues with it. It's a totally different code base than the one I suggested an edit to earlier in this thread, but I think I've implemented a similar fix. @aloisdeniel did a load of work in the dev branch that never made it to master. I'll do what I can to keep an eye on, and watch this branch as best I can. Please bare with me, as I am a busy person, and this sort of production is new to me.
from microcharts.
@aloisdeniel thanks for this great component! I've being used and faced the same problem with label sizes. I`ve created a dependency service to solve that and I hope it helps you, @muhaym, @SteveShepNL and others fans like me :D
PCL
1 - Create an Interface
public interface INativeFont { float GetNativeSize(float size); }
2 - Set chart label size
var dependency = DependencyService.Get<INativeFont>(); chartView.Chart.LabelTextSize = dependency.GetNativeSize(10);
3 - Create dependencies
Android Get Dip equivalent
[assembly: Xamarin.Forms.Dependency(typeof(NativeFont))] namespace yournamespace.Droid.Dependencies { public class NativeFont : INativeFont { public float GetNativeSize(float size) { var displayMetrics = Android.App.Application.Context.Resources.DisplayMetrics; return TypedValue.ApplyDimension(ComplexUnitType.Dip, size, displayMetrics); } } }
IOS Get scaled equivalent
[assembly: Xamarin.Forms.Dependency(typeof(NativeFont))] namespace yournamespace.iOS.Dependencies { public class NativeFont : INativeFont { public float GetNativeSize(float size) { return size * (float)UIScreen.MainScreen.Scale; } } }
I need this, fixed label issue for different Android devices. Thanks!
from microcharts.
any updayes on this ?
from microcharts.
Related Issues (20)
- [Question] Can Microcharts.Maui be used on .Net Android project? (not MAUI)
- [Question]Stacked barchart HOT 1
- [Question] Donut/Pie Charts (on Xamarin.Android) : How do I get the correct Colors in the Legend
- .Net 7 compatibility issues with Microcharts.Maui
- [Question] How Can I add Text In the Center Of the Dount Chart?
- Xamarin app is crashing when we scroll on multi line chart on the ListView in iOS version.
- [Bug] Microcharts.Maui 1.0.0 Does not work in .NET MAUI 8 HOT 6
- [Question] transferring a legend
- [Bug] - PieChart not centered HOT 1
- [Question] Exception occured on IOS when use all the Chart ,But it works on windows and Andriod HOT 1
- [Feature]I need to support Chinese HOT 1
- [Question] Maui support with Microsoft.Maui.Graphics instead of SkiaSharp HOT 1
- [Bug]Getting Target error when Targeting Maui App to .net 7.0 HOT 2
- [Question] Does Microchart support draw chart at live time HOT 1
- Label value text is not clear while updating ?!
- [Bug] Microcharts.IOS namespace is missing when I upgrade Xamarin.iOS to .net8.0-iOS HOT 1
- [Feature]Can we add a horizontal bar chart?
- [Bug] Publish Nuget Packages (Windows) pipeline fails due to Android 29 not being installed.
- can't change background color in .net maui [Bug]
- [Question] Usage Help. Updating chart does not remove previous chart unless resizing the screen
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microcharts.