bulubuloa / Ultimate-Xamarin-Forms-KIT

A powerful 🚀 Android/iOS chart view / graph view library, binding support for Xamarin.Forms, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, dragging and animations.
https://www.nuget.org/packages/UltimateXF/
121 stars 33 forks source link

chart labels are not properly dispalying on updating the charts #18

Open eliyasbaby opened 5 years ago

eliyasbaby commented 5 years ago

`using System; using System.Collections.Generic; using UltimateXF.Widget.Charts.Models; using UltimateXF.Widget.Charts.Models.BarChart; using UltimateXF.Widget.Charts.Models.Formatters; using Xamarin.Forms;

namespace DemoXF { public partial class BarChartPage : ContentPage { public BarChartPage() { InitializeComponent();

        var entries = new List<EntryChart>();
        var entries2 = new List<EntryChart>();
        var labels = new List<string>();

        Random random = new Random();
        for (int i = 0; i < 6; i++)
        {
            entries.Add(new EntryChart(i, random.Next(20)));
            entries2.Add(new EntryChart(i, random.Next(20)));
            labels.Add("Entry" + i);
        }

        var dataSet4 = new BarDataSet(entries, "Bar DataSet 1")
        {
            Colors = new List<Color>(){
                Color.Accent, Color.Azure, Color.Bisque, Color.Gray, Color.Green, Color.Chocolate, Color.Black
            },
        };
        var dataSet5 = new BarDataSet(entries2, "Bar DataSet 2")
        {
            Colors = new List<Color>{
                Color.Green
            },
        };

        var data4 = new BarChartData(new List<IBarDataSet>() { dataSet4 });

        chart.ChartData = data4;
        chart.DescriptionChart.Text = "Test label chart description";

        chart.AxisLeft.DrawGridLines = false;
        chart.AxisLeft.DrawAxisLine = true;
        chart.AxisLeft.Enabled = true;

        chart.AxisRight.DrawAxisLine = false;
        chart.AxisRight.DrawGridLines = false;
        chart.AxisRight.Enabled = false;

        chart.XAxis.XAXISPosition = XAXISPosition.BOTTOM;
        chart.XAxis.DrawGridLines = false;
        chart.XAxis.AxisValueFormatter = new TextByIndexXAxisFormatter(labels);

    }

    private void OnButtonClick(object sender, EventArgs e)
    {
        var entries = new List<EntryChart>();

        var labels = new List<string>();

        Random random = new Random();
        for (int i = 0; i < 12; i++)
        {
            entries.Add(new EntryChart(i, random.Next(20)));

            labels.Add("Entry" + i);
        }

        var dataSet4 = new BarDataSet(entries, "Bar DataSet 1")
        {
            Colors = new List<Color>(){
                Color.Accent, Color.Azure, Color.Bisque, Color.Gray, Color.Green, Color.Chocolate, Color.Black
            },
        };
        var data4 = new BarChartData(new List<IBarDataSet>() { dataSet4 });
        chart.XAxis.AxisValueFormatter = new TextByIndexXAxisFormatter(labels);

        chart.ChartData = data4;
    }
}

}` if i update the chart with new values labels are showing from from the old list labels

eliyasbaby commented 5 years ago

@bulubuloa @hoangquachaes How to Clear Chart data while updating .

Slm0nB commented 3 years ago

Hi, We are struggling with a similar problem. @eliyasbaby Did you find a solution?

sandy0089 commented 1 year ago

Hey got he solution:

var XAxis = new XAxisConfig
{
     XAXISPosition = XAXISPosition.BOTTOM,
     DrawGridLines = false,
     LabelRotationAngle = -45,
     AxisValueFormatter = new TextByIndexXAxisFormatter(monthLabels),
     LabelCount = monthLabels.Count
};
chart.XAxis = XAxis;