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
DateString
field will always return.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-
DateString
field will always return. [Same as what I am doing right now]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.
I'd suggest something like this:
public static IList<Stock> GetSome(this IList<Stock> input)
{
var result = new List<Stock>();
if (input.Count < 8)
{
return input;
}
else
{
var i = 0;
for (; i < input.Count; ++i)
{
if (i % 8 == 0)
{
result.Add(input[i]);
}
}
if (i % 8 != 0)
{
result.Add(input.Last());
}
}
return result;
}
If the Stocks are not in chronological order, I'd call .Sort() by date on them.
You'll probably like to add null and empty collection checking in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With