I am implementing Telerik Chart with a huge data. The labels on x-axis of the chart are overlapping. I have overcome this problem but it is not reliable for long run.
These are the fields List have:
FieldName DataType
Date DATETIME
DateString STRING
Unit DOUBLE
Price DOUBLE
X-Axis label value comes from DateString
field
Solution I implemented
- The MIN and MAX Date
DateString
field will always return. - For the rest, return those values where weekday is 'Monday'
Here is code-
// Get min and max Date
DateTime minDate = DateTime.Now;
DateTime maxDate = DateTime.Now;
if (dtGas.Rows.Count > 0)
{
minDate = Convert.ToDateTime(dtGas.Compute("MIN([Date])", ""));
maxDate = Convert.ToDateTime(dtGas.Compute("MAX([Date])", ""));
}
// Group by 'Date' and 'DateString' | 'SUM' of Unit and 'Price'
var qGas = from x in dtGas.AsEnumerable()
group x by new
{
Date = x.Field<DateTime>("Date"),
DateString = x.Field<string>("DateString")
} into egroup
let isOne = egroup.Key.Date.DayOfWeek.ToString() == "Monday"
select new
{
Date = egroup.Key.Date,
DateString = minDate == egroup.Key.Date ?
(
egroup.Key.DateString
) :
(
maxDate == egroup.Key.Date ?
(
egroup.Key.DateString
) :
(
(isOne) ?
(
egroup.Key.DateString
) :
(" ")
)
),
Unit = egroup.Sum(r => r.Field<double>("Unit")),
Price = egroup.Sum(r => r.Field<double>("Price")),
};
This solution helps to return not all values but some of them. Hence avoiding overlapping. But in future as data grows, even this solution will fail.
Solution I need to implement
An idea that I was thinking but don't know how to implement is-
- The MIN and MAX Date
DateString
field will always return. [Same as what I am doing right now] - Return 8 values in intervals from MIN and MAX date regardless of total count of List Item.
2.a. But if List count is less than or equals to 8 then return all values.
So, for example, if in List I have 32 values. It should return me total 10 values in DateString field and rest will be empty string.