GithubHelp home page GithubHelp logo

Comments (17)

rafelton avatar rafelton commented on August 23, 2024 5

@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.

muhaym avatar muhaym commented on August 23, 2024 3

Label font size doesn't seems to be working properly on Android, different version of Android renders in different way.

from microcharts.

SvenHerr avatar SvenHerr commented on August 23, 2024 3

@rafelton

That works but then i also need a Padding because the texts are cutted on the bottom :(

from microcharts.

rerickson1 avatar rerickson1 commented on August 23, 2024 3

Any update on this? It would be great to get the native font size solution implemented in the library.

from microcharts.

aloisdeniel avatar aloisdeniel commented on August 23, 2024 2

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.

aloisdeniel avatar aloisdeniel commented on August 23, 2024 1

I forgot, but you should already have access to a LabelFontSize property available from Chart instances.

from microcharts.

SteveShepNL avatar SteveShepNL commented on August 23, 2024 1

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.

mrxten avatar mrxten commented on August 23, 2024

And also I suggest add rotate labels functional in bar, line charts like in oxyplot. It's needed for fit full text.

from microcharts.

Nixon-Joseph avatar Nixon-Joseph commented on August 23, 2024

@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.

image

from microcharts.

Calvin-2DWeb avatar Calvin-2DWeb commented on August 23, 2024

I'm also waiting a solution

from microcharts.

Nixon-Joseph avatar Nixon-Joseph commented on August 23, 2024

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.

Nixon-Joseph avatar Nixon-Joseph commented on August 23, 2024

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.

rerickson1 avatar rerickson1 commented on August 23, 2024

@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.

Nixon-Joseph avatar Nixon-Joseph commented on August 23, 2024

@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.

Nixon-Joseph avatar Nixon-Joseph commented on August 23, 2024

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.

rpascalegh avatar rpascalegh commented on August 23, 2024

@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.

AbdChahid avatar AbdChahid commented on August 23, 2024

any updayes on this ?

from microcharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.