Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

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

Open
eliyasbaby opened this issue Jun 12, 2019 · 3 comments
Open

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

eliyasbaby opened this issue Jun 12, 2019 · 3 comments

Comments

@eliyasbaby
Copy link

`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
Copy link
Author

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

@Slm0nB
Copy link

Slm0nB commented Apr 6, 2021

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

@sandy0089
Copy link

sandy0089 commented May 25, 2023

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;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants