Dates Show Up Without Data

Charts for Silverlight Forum

Posted 7 years ago by Laura
Version: 15.1.0192

While this data is correct there is an unessicary date duplicate on the X axis.


using System.Windows.Controls;
using Adapt.Model.TaskManagement;
using System;
using Adapt.Model.TaskManagement.Custom;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using ActiproSoftware.Windows.Controls.Charts.Primitives;
using ActiproSoftware.Windows.Controls.Charts;
using System.Linq;
using System.Diagnostics;

namespace HoursChart
    public partial class MainPage : UserControl
        public MainPage()

            //Generate random cost data
            var random = new Random();
            var dataSize = 5;
            var costs = new List<CostInfoCustom>();
            for (int i = 0; i < 10; i++)
                costs.Add(new CostInfoCustom { Qty = random.Next(1, dataSize), CostDate = new DateTime(2012, 01, random.Next(1, dataSize), 12, 0, 0), TaskInfoKey = new TaskInfo { TaskNo = random.Next(1, dataSize) } });

            //Set the chart to use the generated cost data

        private void SetChartData(List<CostInfoCustom> costs)

            //Set the X origin to 0, the interval to 1 hour and display a maximum of 24 hours
            HourChart.YAxes.Add(new XYDecimalAxis { Minimum = 0, TickMajorInterval = 1, Maximum = 24 });
            HourChart.IsLegendVisible = true;

            //Group costs by date and get all the task numbers from the data
            var costsByDates = costs.GroupBy(c => c.CostDate);
            var allTaskNumbers = costs.Select(x => x.TaskInfoKey.TaskNo);

            //For each day add qty = 0 records where a task is missing for that day
            foreach (var costsByDay in costsByDates)
                var missingTaskNumbers = allTaskNumbers.Except(costsByDay.Select(x => x.TaskInfoKey.TaskNo)).ToList();
                foreach (int taskNumber in missingTaskNumbers)
                    costs.Add(new CostInfoCustom { Qty = 0, CostDate = costsByDay.Key, TaskInfoKey = new TaskInfo { TaskNo = taskNumber } });

            //group the costs by task
            var costsGroupedByTaskNo = costs.GroupBy(c => c.TaskInfoKey.TaskNo);

            //for each task's costs, create a data series.
            foreach (var taskCosts in costsGroupedByTaskNo)
                Debug.WriteLine("TaskNo: " + taskCosts.Key + " - Total Hours: " + taskCosts.Sum(x => x.Qty) + " On Days: " + string.Join(", ", taskCosts.Select(cg => cg.CostDate.Day).Distinct()));

                HourChart.Series.Add(new BarSeries { ItemsSource = taskCosts.ToList(), YPath = "Qty", XPath = "CostDate", StackKind = XYSeriesStackKind.Normal, Description = "Task No " + taskCosts.Key });




        <Style TargetType="charts:XYChart">
            <Setter Property="Width" Value="1000" />
            <Setter Property="Height" Value="900" />

        <charts:XYChart Name="HourChart"/>


Comments (1)

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Laura,

When using date/time data, you should generally specify the XYDateTimeAxis yourself so that you can set an appropriate SlotIntervalUnit and SlotInterval properties. That might help in this scenario.

But if not, for complex scenarios like this that require debugging, we always ask that instead of posting code here in the forums where it's not complete, please make a zip of a new simple sample project like this example (but with all the source code) and email that to our support address. The sample should contain as few data points as possible to repro the issue and have no references to external assemblies of your own.

In your email, mention this thread and tell us what you see and what you expect to see. Also be sure to rename the .zip file extension so it doesn't get spam blocked. Then we'll debug that and tell you what the problem is. Thanks!

Actipro Software Support

The latest build of this product (v2018.1 build 0233) was released 3 years ago, which was after the last post in this thread.