简体   繁体   中英

C# Chart - data is repeated

I have the following Data (from the database):

在此处输入图片说明

These are stored in objects that are stored in a list:

for creating the chart series i have created the following function:

public void CreateSeries(DateTime seriesTime)
{
    while (true)
    {
        if (seriesTime.Date > _stopDate.Date) return;
        foreach (var data in _datalist)
        {
            var currentData = (Email)data;
            String xLabel;
            switch (_timeType)
            {
                case DateUtils.TimeType.Weeks:
                    xLabel = seriesTime.Date.ToString("dd");
                    break;
                case DateUtils.TimeType.Months:
                    xLabel = seriesTime.Date.ToString("MM");
                    break;
                case DateUtils.TimeType.Years:
                    xLabel = seriesTime.Date.ToString("yyyy");
                    break;
                default:
                    xLabel = seriesTime.Date.ToString("dd");
                    break;
            }
            AddData(currentData, xLabel);
        }

        if (DateConverter.GetDaysBetween(seriesTime, _stopDate) >= 0)
        {
            seriesTime = AppendDays(seriesTime);
            continue;
        }
        break;
    }
}

protected DateTime AppendDays(DateTime initialDateTime)
{
    switch (_timeType)
    {
        case DateUtils.TimeType.Weeks:
            initialDateTime = initialDateTime.AddDays(7);
            break;
        case DateUtils.TimeType.Months:
            initialDateTime = initialDateTime.AddMonths(1);
            break;
        case DateUtils.TimeType.Years:
            initialDateTime =  initialDateTime.AddYears(1);
            break;
        default:
            initialDateTime = initialDateTime.AddDays(1);
            break;
    }
    return initialDateTime;
}

All of which executes without any issues.

Then when the series have been added i use the following loop in my Form class:

List<Series> chart = ((EmailModel)_controller.GetFactory().GetModel("Email")).GetEmailChart(from, to, current_timetype);
test_chart.Series.Clear();
foreach (Series s in chart)
{
    test_chart.Series.Add(s);
}

Which produces the following chart:

在此处输入图片说明

if you look closely then you will see that it has repeated the data 7 times.

i just don't know what the issue is.

Can anyone tell me what i am doing wrong?

Please tell me if you need more info or code i will check back every often and update my question.

As i see the partern you repeat 7 times 7 column. You have to add 1 serie. Try: test_chart.Series.Add(s);

Whitout the foreach!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM