Ultimate-Xamarin-Forms-KIT icon indicating copy to clipboard operation
Ultimate-Xamarin-Forms-KIT copied to clipboard

Is there a way to set formatted label axes names on Y axes ?

Open ColinLhoest opened this issue 6 years ago • 6 comments

looking for a way to apply new TextByIndexXAxisFormatter(labels); on Y axes

ColinLhoest avatar Jan 07 '19 11:01 ColinLhoest

Yep, i found that bug, You just re-create new XAxisConfig for change labels Eg: var XAsix = new XAxisConfig(); XAsix.XAXISPosition = XAXISPosition.BOTTOM; XAsix.DrawGridLines = false; XAsix.LabelRotationAngle = 90; XAsix.AxisValueFormatter = new TextByIndexXAxisFormatter(labels); chart.XAxis = XAsix;

Its available from 2.3.3-alpha2 version, i will fix this bug at the next version

bulubuloa avatar Feb 24 '19 02:02 bulubuloa

Thanks for your answer, but this overrides the current XAxis labels and it does not reach the expected result. This just rotates labels on X axis and write them on the bottom of the chart. The expected result is to write the labels on the YAxis without overriding XAxis labels.

Thanks for your time

ColinLhoest avatar Mar 04 '19 15:03 ColinLhoest

@etu31327 can you show how you binded x axis labels.because i am not able to set chart.XAxis = XAsix; from MVVM viewmodel. its working from backend c#.

eliyasbaby avatar May 24 '19 05:05 eliyasbaby

@eliyasbaby

in the OnAppearing method in the code behind, I call a public method implemented in my view model that will fill a XAxis property also declared in the view model and then I add it in my chart:

protected override void OnAppearing() { base.OnAppearing(); InitializeComponent(); ((MyViewModel)BindingContext).FillXAxis(); myChart.XAxis = ((MyViewModel)BindingContext).XAxis; };

Here is the called method : public void FormatNightData() { XAxis = ToXAxisLabel(data) }

For example if x labels are hours : `
private XAxisConfig ToXAxisLabel(DateTime[] dateTimes) { XAxisConfig xAxis = new XAxisConfig();

        xAxis.DrawGridLines = false;
        xAxis.XAXISPosition = 0;
        var labels = new List<string>();

        foreach (DateTime dateTime in dateTimes)
        {
            labels.Add(dateTime.ToString("HH:mm"));
        }
        xAxis.AxisValueFormatter = new TextByIndexXAxisFormatter(labels);

        return xAxis;
    }`

ColinLhoest avatar Jun 03 '19 09:06 ColinLhoest

How to change AxisValueFormatter on button click

swapnil591 avatar Dec 19 '19 09:12 swapnil591

How to change AxisValueFormatter on button click

Solved problem by passing list of label to CustomXAxisValueFormatter in place of list of model class.

swapnil591 avatar Dec 19 '19 10:12 swapnil591