Hello,
I have a problem with scrolling in my script. If clicked i must wait minimum 10s for response and than nothing is done. When i didn't use grouping, scrolling was ok, but i need it to show data categorised by date and grouped by name.
I tried setting AutoRange=False and Min/MaxValue based on Date.ToOADate(), unfortunately script is freezing my IE.
MainPage Class:
MainPage XAML:
ViewModel Class:
I appriciate your help.
Adam Tarkowski
I have a problem with scrolling in my script. If clicked i must wait minimum 10s for response and than nothing is done. When i didn't use grouping, scrolling was ok, but i need it to show data categorised by date and grouped by name.
I tried setting AutoRange=False and Min/MaxValue based on Date.ToOADate(), unfortunately script is freezing my IE.
MainPage Class:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
namespace
NewCharting
{
public
partial
class
MainPage : UserControl
{
public
MainPage()
{
InitializeComponent();
}
}
}
MainPage XAML:
<
UserControl
x:Class
=
"NewCharting.MainPage"
xmlns:control
=
"clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
xmlns:chart
=
"clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting"
xmlns:app
=
"clr-namespace:NewCharting"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"1000"
>
<
UserControl.DataContext
>
<
app:PersonalIncomeViewModel
/>
</
UserControl.DataContext
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
control:RadChart
x:Name
=
"RadChart1"
ItemsSource
=
"{Binding DataView}"
>
<
control:RadChart.SeriesMappings
>
<
chart:SeriesMapping
>
<
chart:SeriesMapping.SeriesDefinition
>
<
chart:StackedBarSeriesDefinition
ShowItemLabels
=
"False"
/>
</
chart:SeriesMapping.SeriesDefinition
>
<
chart:SeriesMapping.GroupingSettings
>
<
chart:GroupingSettings
ShouldCreateSeriesForLastGroup
=
"True"
>
<
chart:ChartGroupDescriptor
Member
=
"Date"
/>
<
chart:ChartGroupDescriptor
Member
=
"Name"
/>
</
chart:GroupingSettings
>
</
chart:SeriesMapping.GroupingSettings
>
<
chart:SeriesMapping.ItemMappings
>
<
chart:ItemMapping
DataPointMember
=
"YValue"
FieldName
=
"Income"
AggregateFunction
=
"Sum"
/>
<
chart:ItemMapping
DataPointMember
=
"XCategory"
FieldName
=
"Date"
/>
</
chart:SeriesMapping.ItemMappings
>
<
chart:SeriesMapping.SortDescriptors
>
<
chart:ChartSortDescriptor
Member
=
"Date"
SortDirection
=
"Ascending"
/>
</
chart:SeriesMapping.SortDescriptors
>
</
chart:SeriesMapping
>
</
control:RadChart.SeriesMappings
>
<
control:RadChart.DefaultView
>
<
chart:ChartDefaultView
>
<!--ChartArea-->
<
chart:ChartDefaultView.ChartArea
>
<
chart:ChartArea
LegendName
=
"chartLegend"
EnableAnimations
=
"False"
>
<
chart:ChartArea.AxisX
>
<
chart:AxisX
IsDateTime
=
"True"
DefaultLabelFormat
=
"MMM-y"
MinorTicksVisibility
=
"Visible"
/>
<!-- AutoRange="False" MinValue="{Binding DataDateMinOA}" MaxValue="{Binding DataDateMaxOA}" -->
</
chart:ChartArea.AxisX
>
<
chart:ChartArea.AxisY
>
<
chart:AxisY
DefaultLabelFormat
=
"#VAL{C3}"
MajorGridLinesVisibility
=
"Visible"
MinorTicksVisibility
=
"Collapsed"
StripLinesVisibility
=
"Collapsed"
/>
</
chart:ChartArea.AxisY
>
<
chart:ChartArea.ZoomScrollSettingsX
>
<
chart:ZoomScrollSettings
ScrollMode
=
"ScrollOnly"
RangeEnd
=
"0.5"
/>
</
chart:ChartArea.ZoomScrollSettingsX
>
</
chart:ChartArea
>
</
chart:ChartDefaultView.ChartArea
>
<!--ChartLegend-->
<!--
<
chart:ChartDefaultView.ChartLegend
>
<
chart:ChartLegend
x:Name
=
"chartLegend"
ItemsSource
=
"{Binding DataPersonList}"
/>
</
chart:ChartDefaultView.ChartLegend
>
-->
<!--ChartTitle-->
</
chart:ChartDefaultView
>
</
control:RadChart.DefaultView
>
</
control:RadChart
>
</
Grid
>
</
UserControl
>
ViewModel Class:
using
System;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Ink;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
System.Collections.Generic;
using
Telerik.Windows.Controls;
using
Telerik.Windows.Controls.Charting;
using
Telerik.Windows.Data;
using
System.Linq;
namespace
NewCharting
{
public
class
PersonalIncomeViewModel
{
public
List<PersonalIncome> Data {
get
;
set
; }
public
List<PersonalIncome> DataView {
get
;
set
; }
public
DateTime DataDateMin
{
get
{
return
new
DateTime(Data.Min(d => d.Date.Year), 1, 1); }
}
public
DateTime DataDateMax
{
get
{
return
new
DateTime(Data.Max(d => d.Date.Year) + 1, 1, 1).AddDays(-1); }
}
// public Double DataDateMinOA
// {
// get { return DataDateMin.ToOADate(); }
// }
// public Double DataDateMaxOA
// {
// get { return DataDateMax.ToOADate(); }
// }
// public String ChartScrollRangeMax
// {
// get { return (1 / (DataDateMax.Year - DataDateMin.Year + 1)).ToString() ; }
// }
public
List<String> DataPersonList
{
get
{
return
(from p
in
Data
group p.Name by p.Name into gr
select gr.Key.ToString()).ToList();
}
}
public
PersonalIncomeViewModel()
{
Data = GenerateData();
Data = FillDataFullRange(Data);
DataView = Data;
DataView = (from d
in
Data
group d by
new
{ year = d.Date.Year, month = d.Date.Month, name = d.Name } into gr
select
new
PersonalIncome(){
Name = gr.Key.name,
Income = gr.Sum(o => o.Income),
Date =
new
DateTime(gr.Key.year, gr.Key.month, 1)
}).ToList();
}
public
List<PersonalIncome> GenerateData()
{
return
new
List<PersonalIncome>
{
new
PersonalIncome{ Name =
"Dr. Brown"
,Date = DateTime.Now.AddMonths(5),Income = 12 },
new
PersonalIncome{ Name =
"Dr. Brown"
,Date = DateTime.Now.AddMonths(12),Income = 12 },
new
PersonalIncome{ Name =
"Dr. Brown"
,Date = DateTime.Now.AddMonths(17),Income = 12 },
new
PersonalIncome{ Name =
"Dr. Brown"
,Date = DateTime.Now.AddMonths(5).AddDays(2),Income = 12 },
new
PersonalIncome{ Name =
"Dr. Brown"
,Date = DateTime.Now.AddMonths(4),Income = 15 },
new
PersonalIncome{ Name =
"Dr. Brown"
,Date = DateTime.Now.AddMonths(3),Income = 13 },
new
PersonalIncome{ Name =
"Dr. Down"
,Date = DateTime.Now.AddMonths(2),Income = 14 },
new
PersonalIncome{ Name =
"Dr. Down"
,Date = DateTime.Now.AddMonths(13),Income = 0 },
new
PersonalIncome{ Name =
"Dr. Down"
,Date = DateTime.Now.AddMonths(4),Income = 20 },
new
PersonalIncome{ Name =
"Dr. Down"
,Date = DateTime.Now.AddMonths(5),Income = 22 },
new
PersonalIncome{ Name =
"Dr. Smith"
,Date = DateTime.Now.AddMonths(6),Income = 10 },
new
PersonalIncome{ Name =
"Dr. Smith"
,Date = DateTime.Now.AddMonths(4),Income = 17 },
new
PersonalIncome{ Name =
"Dr. Smith"
,Date = DateTime.Now.AddMonths(2),Income = 5 }
};
}
private
List<PersonalIncome> FillDataFullRange(List<PersonalIncome> data)
{
// fix for custom range in chart
foreach
(var person
in
DataPersonList)
{
for
(var loopYr = DataDateMin.Year; loopYr <= DataDateMax.Year; loopYr++)
for
(var loopMth = 1; loopMth <= 12; loopMth++)
data.Add(
new
PersonalIncome { Name = person, Date =
new
DateTime(loopYr, loopMth, 1), Income = 0 });
}
return
data;
}
}
public
class
PersonalIncome
{
public
String Name {
get
;
set
; }
public
Int32 Income {
get
;
set
; }
public
DateTime Date {
get
;
set
; }
// public Double DateOA { get { return Date.ToOADate(); } }
}
}
I appriciate your help.
Adam Tarkowski