Skip to content

Commit 757ebfb

Browse files
Updated sample
1 parent b086a0d commit 757ebfb

File tree

6 files changed

+334
-109
lines changed

6 files changed

+334
-109
lines changed

DisplayTrackballValues/DisplayTrackballValues/DisplayTrackballValues.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.92" />
6262
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
6363
<PackageReference Include="Syncfusion.Maui.Charts" Version="*" />
64-
<PackageReference Include="Syncfusion.Maui.ListView" Version="*" />
6564
</ItemGroup>
6665

6766
</Project>

DisplayTrackballValues/DisplayTrackballValues/MainPage.xaml

Lines changed: 84 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
44
x:Class="DisplayTrackballValues.MainPage"
55
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
6-
xmlns:listView="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView"
76
xmlns:local="clr-namespace:DisplayTrackballValues">
87

98
<ContentPage.BindingContext>
@@ -30,57 +29,102 @@
3029
<chart:ChartTrackballBehavior ShowLabel="False"/>
3130
</chart:SfCartesianChart.TrackballBehavior>
3231

33-
<chart:LineSeries ItemsSource="{Binding Data}"
32+
<chart:SfCartesianChart.Legend>
33+
<chart:ChartLegend/>
34+
</chart:SfCartesianChart.Legend>
35+
36+
<chart:LineSeries ItemsSource="{Binding ProductSalesDetails}"
37+
x:Name="series1"
3438
StrokeWidth="3"
3539
XBindingPath="Date"
36-
YBindingPath="YValue1"
37-
ShowTrackballLabel="True"
38-
Fill="Pink"/>
39-
<chart:LineSeries ItemsSource="{Binding Data}"
40+
YBindingPath="ProductASales"
41+
ShowTrackballLabel="True"
42+
Label="Product A"
43+
Fill="RoyalBlue"/>
44+
<chart:LineSeries ItemsSource="{Binding ProductSalesDetails}"
45+
x:Name="series2"
4046
StrokeWidth="3"
4147
XBindingPath="Date"
42-
YBindingPath="YValue2"
48+
YBindingPath="ProductBSales"
4349
ShowTrackballLabel="True"
44-
Fill="LightBlue"/>
45-
<chart:LineSeries ItemsSource="{Binding Data}"
50+
Label="Product B"
51+
Fill="HotPink"/>
52+
<chart:LineSeries ItemsSource="{Binding ProductSalesDetails}"
53+
x:Name="series3"
4654
StrokeWidth="3"
4755
XBindingPath="Date"
48-
YBindingPath="YValue3"
56+
YBindingPath="ProductCSales"
4957
ShowTrackballLabel="True"
50-
Fill="LightGreen"/>
58+
Label="Product C"
59+
Fill="Green"/>
5160

5261
</chart:SfCartesianChart>
53-
<VerticalStackLayout Grid.Column="1">
62+
<VerticalStackLayout Grid.Column="1" HorizontalOptions="Center">
5463
<Label HorizontalOptions="Center" Text="Trackball Values" FontAttributes="Bold"/>
55-
<ListView x:Name="listView" >
56-
<ListView.ItemTemplate>
57-
<DataTemplate>
58-
<ViewCell>
59-
<Frame Background="{Binding Series.Fill}" CornerRadius="8" Margin="5" BorderColor="Gray">
60-
<HorizontalStackLayout HorizontalOptions="Center" Spacing="10" VerticalOptions="Center" >
61-
<Label Text="{Binding DataItem.Date, StringFormat='{0:dd/MM/yyyy}'}"
62-
FontSize="14"
63-
FontAttributes="Bold"
64-
TextColor="Black"
65-
VerticalOptions="Center"/>
66-
<Label Text=" : "
67-
FontSize="14"
68-
FontAttributes="Bold"
69-
TextColor="Black"
70-
VerticalOptions="Center"/>
71-
<Label Text="{Binding Label}"
72-
FontSize="14"
73-
FontAttributes="Bold"
74-
TextColor="Black"
75-
VerticalOptions="Center"/>
76-
</HorizontalStackLayout>
77-
</Frame>
78-
</ViewCell>
79-
</DataTemplate>
80-
</ListView.ItemTemplate>
81-
</ListView>
64+
<VerticalStackLayout>
65+
<Frame Background="LightBlue" CornerRadius="8" Margin="5" BorderColor="Gray">
66+
<HorizontalStackLayout HorizontalOptions="Center" Spacing="10" VerticalOptions="Center" >
67+
<Label x:Name="dateLabel1"
68+
FontSize="14"
69+
FontAttributes="Bold"
70+
TextColor="Black"
71+
VerticalOptions="Center"/>
72+
<Label Text=" : "
73+
FontSize="14"
74+
FontAttributes="Bold"
75+
TextColor="Black"
76+
VerticalOptions="Center"/>
77+
<Label x:Name="valueLabel1"
78+
FontSize="14"
79+
FontAttributes="Bold"
80+
TextColor="Black"
81+
VerticalOptions="Center"/>
82+
</HorizontalStackLayout>
83+
</Frame>
84+
</VerticalStackLayout>
85+
<VerticalStackLayout>
86+
<Frame Background="Pink" CornerRadius="8" Margin="5" BorderColor="Gray">
87+
<HorizontalStackLayout HorizontalOptions="Center" Spacing="10" VerticalOptions="Center" >
88+
<Label x:Name="dateLabel2"
89+
FontSize="14"
90+
FontAttributes="Bold"
91+
TextColor="Black"
92+
VerticalOptions="Center"/>
93+
<Label Text=" : "
94+
FontSize="14"
95+
FontAttributes="Bold"
96+
TextColor="Black"
97+
VerticalOptions="Center"/>
98+
<Label x:Name="valueLabel2"
99+
FontSize="14"
100+
FontAttributes="Bold"
101+
TextColor="Black"
102+
VerticalOptions="Center"/>
103+
</HorizontalStackLayout>
104+
</Frame>
105+
</VerticalStackLayout>
106+
<VerticalStackLayout>
107+
<Frame Background="LightGreen" CornerRadius="8" Margin="5" BorderColor="Gray">
108+
<HorizontalStackLayout HorizontalOptions="Center" Spacing="10" VerticalOptions="Center" >
109+
<Label x:Name="dateLabel3"
110+
FontSize="14"
111+
FontAttributes="Bold"
112+
TextColor="Black"
113+
VerticalOptions="Center"/>
114+
<Label Text=" : "
115+
FontSize="14"
116+
FontAttributes="Bold"
117+
TextColor="Black"
118+
VerticalOptions="Center"/>
119+
<Label x:Name="valueLabel3"
120+
FontSize="14"
121+
FontAttributes="Bold"
122+
TextColor="Black"
123+
VerticalOptions="Center"/>
124+
</HorizontalStackLayout>
125+
</Frame>
126+
</VerticalStackLayout>
82127
</VerticalStackLayout>
83-
84128
</Grid>
85129

86130
</ContentPage>

DisplayTrackballValues/DisplayTrackballValues/MainPage.xaml.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,57 @@ public MainPage()
1111

1212
private void chart_TrackballCreated(object sender, TrackballEventArgs e)
1313
{
14-
listView.ItemsSource = e.TrackballPointsInfo.ToList();
14+
var items = e.TrackballPointsInfo;
15+
16+
foreach (var item in items)
17+
{
18+
var series = item.Series;
19+
20+
if (series == series1)
21+
{
22+
item.MarkerSettings = new ChartMarkerSettings()
23+
{
24+
Fill = Colors.DeepSkyBlue,
25+
Width = 15,
26+
Height = 15,
27+
Stroke = Colors.RoyalBlue,
28+
StrokeWidth = 3,
29+
Type = ShapeType.InvertedTriangle
30+
};
31+
dateLabel1.SetBinding(Label.TextProperty, new Binding("Date") { Source = item.DataItem, StringFormat = "{0:dd/MM/yyyy}" });
32+
valueLabel1.SetBinding(Label.TextProperty, new Binding("Label") { Source = item });
33+
}
34+
35+
else if (series == series2)
36+
{
37+
item.MarkerSettings = new ChartMarkerSettings()
38+
{
39+
Fill = Colors.LightPink,
40+
Width = 15,
41+
Height = 15,
42+
Stroke = Colors.HotPink,
43+
StrokeWidth = 3,
44+
Type = ShapeType.Cross
45+
};
46+
dateLabel2.SetBinding(Label.TextProperty, new Binding("Date") { Source = item.DataItem, StringFormat = "{0:dd/MM/yyyy}" });
47+
valueLabel2.SetBinding(Label.TextProperty, new Binding("Label") { Source = item });
48+
}
49+
50+
else if (series == series3)
51+
{
52+
item.MarkerSettings = new ChartMarkerSettings()
53+
{
54+
Fill = Colors.LightSeaGreen,
55+
Width = 15,
56+
Height = 15,
57+
Stroke = Colors.Green,
58+
StrokeWidth = 3,
59+
Type = ShapeType.Diamond
60+
};
61+
dateLabel3.SetBinding(Label.TextProperty, new Binding("Date") { Source = item.DataItem, StringFormat = "{0:dd/MM/yyyy}" });
62+
valueLabel3.SetBinding(Label.TextProperty, new Binding("Label") { Source = item });
63+
}
64+
}
1565
}
1666
}
1767

DisplayTrackballValues/DisplayTrackballValues/Model/Model.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace DisplayTrackballValues
99
public class Model
1010
{
1111
public DateTime Date { get; set; }
12-
public double YValue1 { get; set; }
13-
public double YValue2 { get; set; }
14-
public double YValue3 { get; set; }
12+
public double ProductASales { get; set; }
13+
public double ProductBSales { get; set; }
14+
public double ProductCSales { get; set; }
1515
}
1616
}

DisplayTrackballValues/DisplayTrackballValues/ViewModel/ViewModel.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ namespace DisplayTrackballValues
99
{
1010
public class ViewModel
1111
{
12-
public ObservableCollection<Model> Data { get; set; }
12+
public ObservableCollection<Model> ProductSalesDetails { get; set; }
1313

1414
public ViewModel()
1515
{
16-
Data = new ObservableCollection<Model>();
17-
DateTime startDate = new DateTime(2000, 01, 04);
18-
DateTime endDate = new DateTime(2000, 09, 05);
19-
Data.Add(new Model() { YValue1 = 5, YValue2 = 5, YValue3 = 5, Date = new DateTime(2001, 01, 05) });
20-
Data.Add(new Model() { YValue1 = 10, YValue2 = 15, YValue3 = 13, Date = new DateTime(2001, 03, 06) });
21-
Data.Add(new Model() { YValue1 = 15, YValue2 = 20, YValue3 = 25, Date = new DateTime(2001, 05, 07) });
22-
Data.Add(new Model() { YValue1 = 10, YValue2 = 15, YValue3 = 20, Date = new DateTime(2001, 07, 08) });
23-
Data.Add(new Model() { YValue1 = 25, YValue2 = 20, YValue3 = 35, Date = new DateTime(2001, 09, 09) });
24-
Data.Add(new Model() { YValue1 = 35, YValue2 = 40, YValue3 = 50, Date = new DateTime(2001, 11, 10) });
16+
ProductSalesDetails = new ObservableCollection<Model>();
17+
18+
ProductSalesDetails.Add(new Model() { ProductASales = 5, ProductBSales = 5, ProductCSales = 5, Date = new DateTime(2001, 01, 05) });
19+
ProductSalesDetails.Add(new Model() { ProductASales = 10, ProductBSales = 15, ProductCSales = 13, Date = new DateTime(2001, 03, 06) });
20+
ProductSalesDetails.Add(new Model() { ProductASales = 15, ProductBSales = 20, ProductCSales = 25, Date = new DateTime(2001, 05, 07) });
21+
ProductSalesDetails.Add(new Model() { ProductASales = 10, ProductBSales = 15, ProductCSales = 20, Date = new DateTime(2001, 07, 08) });
22+
ProductSalesDetails.Add(new Model() { ProductASales = 25, ProductBSales = 20, ProductCSales = 35, Date = new DateTime(2001, 09, 09) });
23+
ProductSalesDetails.Add(new Model() { ProductASales = 35, ProductBSales = 40, ProductCSales = 50, Date = new DateTime(2001, 11, 10) });
2524

2625
}
2726
}

0 commit comments

Comments
 (0)