Skip to content

Commit

Permalink
chart added.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonultasmf committed May 10, 2024
1 parent 6b632bd commit bea5839
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 31 deletions.
6 changes: 4 additions & 2 deletions MyFinance/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

global using Microsoft.EntityFrameworkCore;


global using LiveChartsCore;
global using LiveChartsCore.SkiaSharpView;
global using LiveChartsCore.SkiaSharpView.Maui;
global using DevExpress.Maui.Controls;
global using DevExpress.Maui.Editors;
global using DevExpress.Maui.Charts;
global using DevExpress.Maui.CollectionView;
global using DevExpress.Maui.Core;
global using DevExpress.Maui;
Expand All @@ -40,6 +41,7 @@
global using static Microsoft.Maui.LineBreakMode;
global using static Microsoft.Maui.Keyboard;
global using static DevExpress.Maui.Core.DXButtonType;
global using static LiveChartsCore.Measure.ZoomAndPanMode;

global using MC = Microsoft.Maui.Controls;
global using DC = DevExpress.Maui.Controls;
14 changes: 8 additions & 6 deletions MyFinance/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Maui.Controls.Compatibility.Hosting;
using SkiaSharp.Views.Maui.Controls.Hosting;
using DXImage = DevExpress.Maui.Core.DXImage;

namespace MyFinance;
Expand All @@ -7,10 +9,8 @@ namespace MyFinance;
[MauiMarkup(typeof(StatusBarBehavior), typeof(TextEdit), typeof(TextEditBase), typeof(EditBase), typeof(ComboBoxEdit))]
[MauiMarkup(typeof(PasswordEdit), typeof(CheckEdit), typeof(DXPopup), typeof(ComboBoxEditBase), typeof(ItemsEditBase))]
[MauiMarkup(typeof(DXImage), typeof(DXButton), typeof(DXViewBase), typeof(DXBorder), typeof(DXContentPresenterBase))]
[MauiMarkup(typeof(DXContentPresenter), typeof(DXCollectionView), typeof(ChartView), typeof(SeriesCrosshairOptions), typeof(SeriesHintOptions))]
[MauiMarkup(typeof(SeriesHintOptionsBase), typeof(ChartElement), typeof(LineSeries), typeof(ChartSeriesElement), typeof(XYSeries))]
[MauiMarkup(typeof(Series), typeof(SeriesBase), typeof(ChartSeriesElement), typeof(SeriesDataAdapter), typeof(DataSourceAdapterBase))]
[MauiMarkup(typeof(ValueDataMember))]
[MauiMarkup(typeof(DXContentPresenter), typeof(DXCollectionView), typeof(CartesianChart))]

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
Expand All @@ -20,12 +20,14 @@ public static MauiApp CreateMauiApp()
.UseMauiApp<App>()
.UseDevExpress()
.UseMauiCommunityToolkit()
.UseSkiaSharp(true)
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

})
.UseMauiCompatibility();

builder.Logging.AddDebug();

builder.Services
Expand Down
4 changes: 2 additions & 2 deletions MyFinance/MyFinance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="DevExpress.Maui.Charts" Version="24.1.1-alpha-24085" />
<PackageReference Include="DevExpress.Maui.Controls" Version="24.1.1-alpha-24085" />
<PackageReference Include="DevExpress.Maui.Editors" Version="24.1.1-alpha-24085" />
<PackageReference Include="FmgLib.MauiMarkup" Version="8.2.3-prev1.0.1" />
<PackageReference Include="FmgLib.MauiMarkup" Version="8.2.3-prev1.0.3" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.Maui" Version="2.0.0-rc2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" />
Expand Down
69 changes: 69 additions & 0 deletions MyFinance/ViewModels/ChartPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,73 @@

public partial class ChartPageViewModel : BaseViewModel
{
[ObservableProperty]
private string totalBalance;

[ObservableProperty]
private string totalIncome;

[ObservableProperty]
private string totalExpense;
private readonly Random _random = new();
public ChartPageViewModel()
{
TotalBalance = "25,291.50 ₺";
TotalExpense = "2,367.82 ₺";
TotalIncome = "167.82 ₺";
var trend = 100;
var values = new List<int>();

for (var i = 0; i < 100; i++)
{
trend += _random.Next(-30, 50);
values.Add(trend);
}

Series = new ISeries[]
{
new ColumnSeries<int>
{
Values = values
}
};

XAxes = new[] { new Axis() };
}

public ISeries[] Series { get; }

public Axis[] XAxes { get; }

[RelayCommand]
public void GoToPage1()
{
var axis = XAxes[0];
axis.MinLimit = -0.5;
axis.MaxLimit = 10.5;
}

[RelayCommand]
public void GoToPage2()
{
var axis = XAxes[0];
axis.MinLimit = -0.5;
axis.MaxLimit = 20.5;
}

[RelayCommand]
public void GoToPage3()
{
var axis = XAxes[0];
axis.MinLimit = -0.5;
axis.MaxLimit = 30.5;
}

[RelayCommand]
public void SeeAll()
{
var axis = XAxes[0];
axis.MinLimit = null;
axis.MaxLimit = null;
}
}
75 changes: 54 additions & 21 deletions MyFinance/Views/ChartPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,62 @@ public partial class ChartPage(ChartPageViewModel viewModel) : BasePage<ChartPag
public override void Build()
{
this
.Resources(
ResourceDictionaryExtension
.Add(new ResourceDictionary(), "lineSeriesHintOptions", new Style<SeriesCrosshairOptions>(e => e
.PointTextPattern("{}{S}: {V}M")
.ShowInLabel(true)
.AxisLabelVisible(true)
.AxisLineVisible(true)
)
)
)
.Content(
new ChartView()
.Series(
[
new LineSeries()
.DisplayName("deneme")
.Data(
new SeriesDataAdapter()
.ArgumentDataMember("Year")
.DataSource(e => e.Path(""))

new Grid()
.RowDefinitions(e => e.Star(.6).Star(8.8).Star(.6))
.Margin(5)
.Children(
new VerticalStackLayout()
.Spacing(-3)
.Children(
new Label()
.FontAttributes(Bold)
.TextColor(Black)
.Text("Total balance"),

new Grid()
.RowDefinitions(e => e.Star().Star())
.ColumnDefinitions(e => e.Star(7).Star(3))
.Spacing(10, 3)
.Children(
new Label()
.Text(e => e.Path("TotalBalance"))
.FontAttributes(Bold)
.FontSize(40)
.RowSpan(2),

new Label()
.Text(e => e.Path("TotalIncome"))
.TextColor(Green)
.FontSize(12)
.Column(1)
.AlignBottomEnd(),

new Label()
.Text(e => e.Path("TotalExpense"))
.TextColor(Red)
.FontSize(12)
.Column(1)
.Row(1)
.AlignTopEnd()
)
]
),

new CartesianChart()
.Row(1)
.Series(e => e.Path("Series"))
.XAxes(e => e.Path("XAxes"))
.ZoomMode(ZoomX),

new HorizontalStackLayout()
.Row(2)
.Spacing(10)
.Children(
new Button().Command(e => e.Path("GoToPage1Command")).Text("Weeks"),
new Button().Command(e => e.Path("GoToPage2Command")).Text("Month"),
new Button().Command(e => e.Path("GoToPage3Command")).Text("6 Months"),
new Button().Command(e => e.Path("SeeAllCommand")).Text("Clear")
)
)
);
}
Expand Down

0 comments on commit bea5839

Please sign in to comment.