Skip to content

Commit bea5839

Browse files
committed
chart added.
1 parent 6b632bd commit bea5839

File tree

5 files changed

+137
-31
lines changed

5 files changed

+137
-31
lines changed

MyFinance/Imports.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525

2626
global using Microsoft.EntityFrameworkCore;
2727

28-
28+
global using LiveChartsCore;
29+
global using LiveChartsCore.SkiaSharpView;
30+
global using LiveChartsCore.SkiaSharpView.Maui;
2931
global using DevExpress.Maui.Controls;
3032
global using DevExpress.Maui.Editors;
31-
global using DevExpress.Maui.Charts;
3233
global using DevExpress.Maui.CollectionView;
3334
global using DevExpress.Maui.Core;
3435
global using DevExpress.Maui;
@@ -40,6 +41,7 @@
4041
global using static Microsoft.Maui.LineBreakMode;
4142
global using static Microsoft.Maui.Keyboard;
4243
global using static DevExpress.Maui.Core.DXButtonType;
44+
global using static LiveChartsCore.Measure.ZoomAndPanMode;
4345

4446
global using MC = Microsoft.Maui.Controls;
4547
global using DC = DevExpress.Maui.Controls;

MyFinance/MauiProgram.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Microsoft.Extensions.Logging;
2+
using Microsoft.Maui.Controls.Compatibility.Hosting;
3+
using SkiaSharp.Views.Maui.Controls.Hosting;
24
using DXImage = DevExpress.Maui.Core.DXImage;
35

46
namespace MyFinance;
@@ -7,10 +9,8 @@ namespace MyFinance;
79
[MauiMarkup(typeof(StatusBarBehavior), typeof(TextEdit), typeof(TextEditBase), typeof(EditBase), typeof(ComboBoxEdit))]
810
[MauiMarkup(typeof(PasswordEdit), typeof(CheckEdit), typeof(DXPopup), typeof(ComboBoxEditBase), typeof(ItemsEditBase))]
911
[MauiMarkup(typeof(DXImage), typeof(DXButton), typeof(DXViewBase), typeof(DXBorder), typeof(DXContentPresenterBase))]
10-
[MauiMarkup(typeof(DXContentPresenter), typeof(DXCollectionView), typeof(ChartView), typeof(SeriesCrosshairOptions), typeof(SeriesHintOptions))]
11-
[MauiMarkup(typeof(SeriesHintOptionsBase), typeof(ChartElement), typeof(LineSeries), typeof(ChartSeriesElement), typeof(XYSeries))]
12-
[MauiMarkup(typeof(Series), typeof(SeriesBase), typeof(ChartSeriesElement), typeof(SeriesDataAdapter), typeof(DataSourceAdapterBase))]
13-
[MauiMarkup(typeof(ValueDataMember))]
12+
[MauiMarkup(typeof(DXContentPresenter), typeof(DXCollectionView), typeof(CartesianChart))]
13+
1414
public static class MauiProgram
1515
{
1616
public static MauiApp CreateMauiApp()
@@ -20,12 +20,14 @@ public static MauiApp CreateMauiApp()
2020
.UseMauiApp<App>()
2121
.UseDevExpress()
2222
.UseMauiCommunityToolkit()
23+
.UseSkiaSharp(true)
2324
.ConfigureFonts(fonts =>
2425
{
2526
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
2627
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
27-
});
28-
28+
})
29+
.UseMauiCompatibility();
30+
2931
builder.Logging.AddDebug();
3032

3133
builder.Services

MyFinance/MyFinance.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
<ItemGroup>
6464
<PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" />
6565
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
66-
<PackageReference Include="DevExpress.Maui.Charts" Version="24.1.1-alpha-24085" />
6766
<PackageReference Include="DevExpress.Maui.Controls" Version="24.1.1-alpha-24085" />
6867
<PackageReference Include="DevExpress.Maui.Editors" Version="24.1.1-alpha-24085" />
69-
<PackageReference Include="FmgLib.MauiMarkup" Version="8.2.3-prev1.0.1" />
68+
<PackageReference Include="FmgLib.MauiMarkup" Version="8.2.3-prev1.0.3" />
69+
<PackageReference Include="LiveChartsCore.SkiaSharpView.Maui" Version="2.0.0-rc2" />
7070
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
7171
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" />
7272
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" />

MyFinance/ViewModels/ChartPageViewModel.cs

+69
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,73 @@
22

33
public partial class ChartPageViewModel : BaseViewModel
44
{
5+
[ObservableProperty]
6+
private string totalBalance;
7+
8+
[ObservableProperty]
9+
private string totalIncome;
10+
11+
[ObservableProperty]
12+
private string totalExpense;
13+
private readonly Random _random = new();
14+
public ChartPageViewModel()
15+
{
16+
TotalBalance = "25,291.50 ₺";
17+
TotalExpense = "2,367.82 ₺";
18+
TotalIncome = "167.82 ₺";
19+
var trend = 100;
20+
var values = new List<int>();
21+
22+
for (var i = 0; i < 100; i++)
23+
{
24+
trend += _random.Next(-30, 50);
25+
values.Add(trend);
26+
}
27+
28+
Series = new ISeries[]
29+
{
30+
new ColumnSeries<int>
31+
{
32+
Values = values
33+
}
34+
};
35+
36+
XAxes = new[] { new Axis() };
37+
}
38+
39+
public ISeries[] Series { get; }
40+
41+
public Axis[] XAxes { get; }
42+
43+
[RelayCommand]
44+
public void GoToPage1()
45+
{
46+
var axis = XAxes[0];
47+
axis.MinLimit = -0.5;
48+
axis.MaxLimit = 10.5;
49+
}
50+
51+
[RelayCommand]
52+
public void GoToPage2()
53+
{
54+
var axis = XAxes[0];
55+
axis.MinLimit = -0.5;
56+
axis.MaxLimit = 20.5;
57+
}
58+
59+
[RelayCommand]
60+
public void GoToPage3()
61+
{
62+
var axis = XAxes[0];
63+
axis.MinLimit = -0.5;
64+
axis.MaxLimit = 30.5;
65+
}
66+
67+
[RelayCommand]
68+
public void SeeAll()
69+
{
70+
var axis = XAxes[0];
71+
axis.MinLimit = null;
72+
axis.MaxLimit = null;
73+
}
574
}

MyFinance/Views/ChartPage.cs

+54-21
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,62 @@ public partial class ChartPage(ChartPageViewModel viewModel) : BasePage<ChartPag
55
public override void Build()
66
{
77
this
8-
.Resources(
9-
ResourceDictionaryExtension
10-
.Add(new ResourceDictionary(), "lineSeriesHintOptions", new Style<SeriesCrosshairOptions>(e => e
11-
.PointTextPattern("{}{S}: {V}M")
12-
.ShowInLabel(true)
13-
.AxisLabelVisible(true)
14-
.AxisLineVisible(true)
15-
)
16-
)
17-
)
188
.Content(
19-
new ChartView()
20-
.Series(
21-
[
22-
new LineSeries()
23-
.DisplayName("deneme")
24-
.Data(
25-
new SeriesDataAdapter()
26-
.ArgumentDataMember("Year")
27-
.DataSource(e => e.Path(""))
28-
9+
new Grid()
10+
.RowDefinitions(e => e.Star(.6).Star(8.8).Star(.6))
11+
.Margin(5)
12+
.Children(
13+
new VerticalStackLayout()
14+
.Spacing(-3)
15+
.Children(
16+
new Label()
17+
.FontAttributes(Bold)
18+
.TextColor(Black)
19+
.Text("Total balance"),
20+
21+
new Grid()
22+
.RowDefinitions(e => e.Star().Star())
23+
.ColumnDefinitions(e => e.Star(7).Star(3))
24+
.Spacing(10, 3)
25+
.Children(
26+
new Label()
27+
.Text(e => e.Path("TotalBalance"))
28+
.FontAttributes(Bold)
29+
.FontSize(40)
30+
.RowSpan(2),
31+
32+
new Label()
33+
.Text(e => e.Path("TotalIncome"))
34+
.TextColor(Green)
35+
.FontSize(12)
36+
.Column(1)
37+
.AlignBottomEnd(),
38+
39+
new Label()
40+
.Text(e => e.Path("TotalExpense"))
41+
.TextColor(Red)
42+
.FontSize(12)
43+
.Column(1)
44+
.Row(1)
45+
.AlignTopEnd()
2946
)
30-
]
47+
),
48+
49+
new CartesianChart()
50+
.Row(1)
51+
.Series(e => e.Path("Series"))
52+
.XAxes(e => e.Path("XAxes"))
53+
.ZoomMode(ZoomX),
54+
55+
new HorizontalStackLayout()
56+
.Row(2)
57+
.Spacing(10)
58+
.Children(
59+
new Button().Command(e => e.Path("GoToPage1Command")).Text("Weeks"),
60+
new Button().Command(e => e.Path("GoToPage2Command")).Text("Month"),
61+
new Button().Command(e => e.Path("GoToPage3Command")).Text("6 Months"),
62+
new Button().Command(e => e.Path("SeeAllCommand")).Text("Clear")
63+
)
3164
)
3265
);
3366
}

0 commit comments

Comments
 (0)