Skip to content

Commit

Permalink
Merge pull request #1 from SyncfusionExamples/MAUI-880461-Updating-cu…
Browse files Browse the repository at this point in the history
…stomized-dot-NET-MAUI-Bar-Chart-blog-sample

MAUI 880461 Updating customized dot NET MAUI Bar Chart blog sample
  • Loading branch information
SyncfusionKarthikeyan authored Apr 4, 2024
2 parents 85fbee3 + ce21109 commit 5433d86
Show file tree
Hide file tree
Showing 42 changed files with 1,718 additions and 2 deletions.
406 changes: 404 additions & 2 deletions README.md

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34701.34
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenewableEnergyJobs", "RenewableEnergyJobs\RenewableEnergyJobs.csproj", "{98F2C3A4-DE35-4F32-96BA-582C1A856203}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{98F2C3A4-DE35-4F32-96BA-582C1A856203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98F2C3A4-DE35-4F32-96BA-582C1A856203}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98F2C3A4-DE35-4F32-96BA-582C1A856203}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{98F2C3A4-DE35-4F32-96BA-582C1A856203}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98F2C3A4-DE35-4F32-96BA-582C1A856203}.Release|Any CPU.Build.0 = Release|Any CPU
{98F2C3A4-DE35-4F32-96BA-582C1A856203}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CAE4C46D-9D0F-497B-A374-E998285BD9C0}
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RenewableEnergyJobs"
x:Class="RenewableEnergyJobs.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
12 changes: 12 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace RenewableEnergyJobs
{
public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new MainPage();
}
}
}
15 changes: 15 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="RenewableEnergyJobs.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RenewableEnergyJobs"
Shell.FlyoutBehavior="Disabled"
Title="RenewableEnergyJobs">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
10 changes: 10 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace RenewableEnergyJobs
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using Syncfusion.Maui.Charts;

namespace RenewableEnergyJobs
{
public class ColumnSeriesExt : ColumnSeries
{
protected override ChartSegment CreateSegment()
{
return new ColumnSegmentExt();
}
}

public class ColumnSegmentExt : ColumnSegment
{
int innerRectCount = 1;
float innerRectHalfWidth = 0;
float pathHeadRadius = 0;
protected override void Draw(ICanvas canvas)
{
if (Series is ChartSeries series && series.BindingContext is JobsViewModel viewModel)
{
RectF segmentRect = new RectF(Left, Top, Right - Left, Bottom - Top);

canvas.SaveState();
canvas.ClipRectangle(segmentRect);
RectF rect = new RectF() { X = Left, Y = Top, Width = Right - Left, Height = Bottom - Top - viewModel.bottomRectHeight };
Brush segmentColor = series.PaletteBrushes[Index];
RectF innerRect = new RectF() { X = rect.X, Y = rect.Y, Width = viewModel.innerRectWidth, Height = rect.Height };// width mac 25

for (float i = innerRect.X; i < rect.Width; i++)
{
innerRect.X = i;
i += innerRect.Width;
innerRectHalfWidth = innerRect.X + innerRect.Width / 2;
pathHeadRadius = innerRect.Width / 4.5f;

canvas.SaveState();
PathF path = new PathF();

if (innerRectCount % 2 != 0)
{
DrawFemalePath(innerRect, innerRectHalfWidth, pathHeadRadius, ref path);
}
else
{
DrawMalePath(innerRect, innerRectHalfWidth, pathHeadRadius, ref path);
}

canvas.SetFillPaint(segmentColor, innerRect);
canvas.FillCircle(innerRectHalfWidth, innerRect.Y + pathHeadRadius, pathHeadRadius);
canvas.FillPath(path);
canvas.RestoreState();
innerRectCount++;
}

RectF bottomRect = new RectF(rect.X, rect.Bottom, rect.Width, viewModel.bottomRectHeight);
canvas.SetFillPaint(segmentColor, bottomRect);
canvas.FillRectangle(bottomRect);
canvas.RestoreState();
}
}

private void DrawFemalePath(RectF innerRect, float innerRectHalfWidth, float pathHeadRadius, ref PathF path)
{
//To draw female dress detail
path.MoveTo(innerRectHalfWidth - pathHeadRadius, innerRect.Y + (innerRect.Height / 4));
path.LineTo(innerRectHalfWidth + pathHeadRadius, innerRect.Y + (innerRect.Height / 4));
path.LineTo(innerRectHalfWidth + (innerRect.Width / 3), innerRect.Bottom - (innerRect.Height / 6));
path.LineTo(innerRectHalfWidth - (innerRect.Width / 3), innerRect.Bottom - (innerRect.Height / 6));
path.Close();
//To draw female right leg
path.MoveTo(innerRectHalfWidth - (pathHeadRadius / 4), innerRect.Bottom - (innerRect.Height / 6));
path.LineTo(innerRectHalfWidth - (pathHeadRadius / 4), innerRect.Bottom);
path.LineTo(innerRectHalfWidth - pathHeadRadius, innerRect.Bottom);
path.LineTo(innerRectHalfWidth - pathHeadRadius, innerRect.Bottom - (innerRect.Height / 6));
path.Close();
//To draw female left leg
path.MoveTo(innerRectHalfWidth + (pathHeadRadius / 4), innerRect.Bottom - (innerRect.Height / 6));
path.LineTo(innerRectHalfWidth + (pathHeadRadius / 4), innerRect.Bottom);
path.LineTo(innerRectHalfWidth + pathHeadRadius, innerRect.Bottom);
path.LineTo(innerRectHalfWidth + pathHeadRadius, innerRect.Bottom - (innerRect.Height / 6));
path.Close();
//To draw female right arm
path.MoveTo(innerRectHalfWidth - pathHeadRadius, innerRect.Y + (innerRect.Height / 4));
path.LineTo(innerRect.X, innerRect.Bottom - (innerRect.Height / 3));
path.LineTo(innerRect.X + (float)(innerRect.Width / 8), innerRect.Bottom - (innerRect.Height / 3));
//To draw female left arm
path.MoveTo(innerRectHalfWidth + pathHeadRadius, innerRect.Y + (innerRect.Height / 4));
path.LineTo(innerRect.Right, innerRect.Bottom - (innerRect.Height / 3));
path.LineTo(innerRect.Right - (float)(innerRect.Width / 8), innerRect.Bottom - (innerRect.Height / 3));
}

private void DrawMalePath(RectF innerRect, float innerRectHalfWidth, float pathHeadRadius, ref PathF path)
{
//To draw male dress detail
path.MoveTo(innerRectHalfWidth - (pathHeadRadius / 4 + pathHeadRadius), innerRect.Y + (innerRect.Height / 4));
path.LineTo(innerRectHalfWidth + (pathHeadRadius / 4 + pathHeadRadius), innerRect.Y + (innerRect.Height / 4));
path.LineTo(innerRectHalfWidth + (pathHeadRadius / 4 + pathHeadRadius), innerRect.Bottom - (innerRect.Height / 3));
path.LineTo(innerRectHalfWidth - (pathHeadRadius / 4 + pathHeadRadius), innerRect.Bottom - (innerRect.Height / 3));
path.Close();
//To draw male right leg
path.MoveTo(innerRectHalfWidth - (pathHeadRadius / 6), innerRect.Bottom - (innerRect.Height / 3));
path.LineTo(innerRectHalfWidth - (pathHeadRadius / 6), innerRect.Bottom);
path.LineTo(innerRectHalfWidth - pathHeadRadius, innerRect.Bottom);
path.LineTo(innerRectHalfWidth - pathHeadRadius, innerRect.Bottom - (innerRect.Height / 3));
path.Close();
//To draw male left leg
path.MoveTo(innerRectHalfWidth + (pathHeadRadius / 6), innerRect.Bottom - (innerRect.Height / 3));
path.LineTo(innerRectHalfWidth + (pathHeadRadius / 6), innerRect.Bottom);
path.LineTo(innerRectHalfWidth + pathHeadRadius, innerRect.Bottom);
path.LineTo(innerRectHalfWidth + pathHeadRadius, innerRect.Bottom - (innerRect.Height / 3));
path.Close();
//To draw male right arm
path.MoveTo(innerRectHalfWidth - (pathHeadRadius / 4 + pathHeadRadius), innerRect.Y + (innerRect.Height / 5));
path.LineTo(innerRect.X, innerRect.Bottom - (innerRect.Height / 3));
path.LineTo(innerRect.X + (float)(innerRect.Width / 6), innerRect.Bottom - (innerRect.Height / 3));
//To draw male left arm
path.MoveTo(innerRectHalfWidth + (pathHeadRadius / 4 + pathHeadRadius), innerRect.Y + (innerRect.Height / 5));
path.LineTo(innerRect.Right, innerRect.Bottom - (innerRect.Height / 3));
path.LineTo(innerRect.Right - (float)(innerRect.Width / 6), innerRect.Bottom - (innerRect.Height / 3));
}
}
}
102 changes: 102 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="RenewableEnergyJobs.MainPage"
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
xmlns:local="clr-namespace:RenewableEnergyJobs">

<Border Stroke="#293b0b" Padding="{OnPlatform Default=10, Android=7,iOS=7}"
StrokeShape="RoundRectangle 10" Margin="{OnPlatform Default=25, Android=10, iOS=20}"
StrokeThickness="1.5">

<chart:SfCartesianChart IsTransposed="True" x:Name="Chart1" HorizontalOptions="Fill" VerticalOptions="FillAndExpand"
Margin="{OnPlatform iOS='-35, 0, 0, 0'}">

<chart:SfCartesianChart.BindingContext>
<local:JobsViewModel/>
</chart:SfCartesianChart.BindingContext>

<chart:SfCartesianChart.Title>
<HorizontalStackLayout >
<Image Source="icon.png" Margin="{OnPlatform Default='5,0,5,0', Android='0,0,5,0', iOS='0,0,5,0'}"
HeightRequest="{OnPlatform Android=30, Default=40, iOS= 40}"/>
<Label Text="Global Employment in Renewable Energy Technologies, 2022"
FontFamily="OpenSansSemibold" Margin="{OnPlatform Default='0,0,0,5', Android='0', iOS='0'}"
HorizontalOptions="Center" HorizontalTextAlignment="Center"
VerticalOptions="Center" FontSize="{OnPlatform Default=18, iOS=22, MacCatalyst=24}" TextColor="Black"/>
</HorizontalStackLayout>
</chart:SfCartesianChart.Title>

<chart:SfCartesianChart.PlotAreaBackgroundView>
<AbsoluteLayout>
<Image Source="background.jpg"
AbsoluteLayout.LayoutBounds="1, 1,-1,-1"
AbsoluteLayout.LayoutFlags="PositionProportional"
HeightRequest="{OnPlatform Android=150,iOS=200, MacCatalyst=400, Default=250}"
WidthRequest="{OnPlatform Android=150,iOS=150, MacCatalyst=300, Default=200}"/>
</AbsoluteLayout>
</chart:SfCartesianChart.PlotAreaBackgroundView>

<chart:SfCartesianChart.ZoomPanBehavior>
<chart:ChartZoomPanBehavior EnableDirectionalZooming="False" EnableDoubleTap="False" EnablePinchZooming="False"
EnableSelectionZooming="False" />
</chart:SfCartesianChart.ZoomPanBehavior>

<chart:SfCartesianChart.XAxes>

<chart:CategoryAxis EdgeLabelsDrawingMode="Shift" LabelPlacement="BetweenTicks" ShowMajorGridLines="False"
AutoScrollingMode="{OnPlatform Android='End', iOS='End'}"
AutoScrollingDelta="{OnPlatform Android='6', iOS='6'}">

<chart:CategoryAxis.MajorTickStyle>
<chart:ChartAxisTickStyle StrokeWidth="0"/>
</chart:CategoryAxis.MajorTickStyle>

<chart:CategoryAxis.LabelStyle>
<chart:ChartAxisLabelStyle Margin="{OnPlatform WinUI='0,4,4,0',Android='0',MacCatalyst='0,4,0,0',iOS='0, 4, 0, 0'}"
FontSize="{OnPlatform MacCatalyst=20, iOS=15}" TextColor="Black"
FontFamily="{OnPlatform WinUI=OpenSansSemibold, iOS=OpenSansSemibold, Android=OpenSansSemibold }"
FontAttributes="Italic"/>
</chart:CategoryAxis.LabelStyle>

</chart:CategoryAxis>
</chart:SfCartesianChart.XAxes>

<chart:SfCartesianChart.YAxes>

<chart:NumericalAxis x:Name="yAxis" Minimum="0" Interval="500" Maximum="5000"
ShowMajorGridLines="False" EdgeLabelsDrawingMode="Center"
ShowMinorGridLines="False" PlotOffsetEnd="50">

<chart:NumericalAxis.LabelStyle>
<chart:ChartAxisLabelStyle x:Name="labelStyle" TextColor="Black" FontAttributes="Italic"
FontSize="{OnPlatform MacCatalyst=20, iOS=15}" FontFamily="OpenSansSemibold" />
</chart:NumericalAxis.LabelStyle>

</chart:NumericalAxis>
</chart:SfCartesianChart.YAxes>

<chart:SfCartesianChart.Series>

<local:ColumnSeriesExt ShowDataLabels="True" x:Name="barSeries" PaletteBrushes="{Binding SeriesPaletteBrushes}"
ItemsSource="{Binding EmploymentDetails}" XBindingPath="Technology"
YBindingPath="Jobs" >

<chart:ColumnSeries.DataLabelSettings>
<chart:CartesianDataLabelSettings LabelPlacement="Outer" UseSeriesPalette="False">

<chart:CartesianDataLabelSettings.LabelStyle>
<chart:ChartDataLabelStyle FontSize="{OnPlatform MacCatalyst=20, iOS=18, Default=Medium}"
FontFamily="{OnPlatform WinUI=OpenSansSemibold, Android=OpenSansSemibold }"/>
</chart:CartesianDataLabelSettings.LabelStyle>

</chart:CartesianDataLabelSettings>
</chart:ColumnSeries.DataLabelSettings>
</local:ColumnSeriesExt>
</chart:SfCartesianChart.Series>

</chart:SfCartesianChart>

</Border>

</ContentPage>
23 changes: 23 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Syncfusion.Maui.Charts;

namespace RenewableEnergyJobs
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();

#if !ANDROID && !IOS
ChartAxisTitle title = new ChartAxisTitle()
{
Text = "Jobs (Thousands)",
FontAttributes = FontAttributes.Bold,
TextColor = Colors.Black,
FontSize = labelStyle.FontSize,
};
yAxis.Title = title;
#endif
}
}
}
27 changes: 27 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using Syncfusion.Maui.Core.Hosting;

namespace RenewableEnergyJobs
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureSyncfusionCore()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
8 changes: 8 additions & 0 deletions RenewableEnergyJobs/RenewableEnergyJobs/Model/JobsModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace RenewableEnergyJobs
{
public class JobsModel
{
public string? Technology { get; set; }
public double Jobs { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace RenewableEnergyJobs
{
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ScreenOrientation = ScreenOrientation.Landscape, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
}
Loading

0 comments on commit 5433d86

Please sign in to comment.