Skip to content

Commit

Permalink
Merge pull request #1 from SyncfusionExamples/WinUI-848397-Stacked-Ar…
Browse files Browse the repository at this point in the history
…ea-Chart

Creating a Stacked Area Chart for U.S Primary Energy Consumption
  • Loading branch information
SyncfusionKarthikeyan committed Sep 21, 2023
2 parents ebbc258 + c440660 commit 0021029
Show file tree
Hide file tree
Showing 25 changed files with 1,114 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# Creating-a-Stacked-Area-Chart-for-U.S.-Primary-Energy-Consumption
This sample demonstrates how to create a Stacked Area Chart for U.S. Primary Energy Consumption.

The [StackedAreaSeries](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.Charts.StackedAreaSeries.html) is representing the multiple of area series are stacked vertically one above the other.

### Introduction

Here, we will explain about stacked area chart to visualize the energy utility consumption of Coal, PetroleumLiquid, PetroleumCoke, Conventional HydroElectric, Nuclear and NaturalGas using WinUI cartesian chart.

Primary energy utility consumption in the United States refers to the amount of energy consumed by various sectors of the economy, such as residential, commercial, industrial, and transportation, before any conversion or transformation. This energy consumption is measured in terms of the raw energy sources used, including fossil fuels (such as coal, natural gas, and petroleum), renewable sources (such as hydroelectric, solar, wind), and nuclear energy.

### Customize chart tooltip behavior

We can customize the tooltip value using the TooltipBehavior in the SfCartesianChart by initializing the ChartTooltipBehavior class.
By using the Duration property, we can set how long the tooltip value is displayed while hovering the mouse over the series, and we can animate the tooltip value using the EnableAnimation property.
Additionally, we can customize the appearance of the tooltip using the Style property in the ChartTooltipBehavior.


### Configure chart zoom pan behavior

We can display the chart area while zoomed in by enabling panning using the EnablePanning property. To prevent pinch zooming and mouse wheel zooming actions, we can disable them using the EnablePinchZooming and EnableMouseWheelZooming properties, respectively.

### Output

![StackedAreaChart_Output](https://github.com/SyncfusionExamples/Creating-a-Stacked-Area-Chart-for-U.S.-Primary-Energy-Consumption/assets/105482474/2af3e7da-97c4-4591-b214-af346a392ccd)
16 changes: 16 additions & 0 deletions US_Energy_Consumption/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Application
x:Class="US_Energy_Consumption.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:US_Energy_Consumption">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
</ResourceDictionary>
</Application.Resources>
</Application>
50 changes: 50 additions & 0 deletions US_Energy_Consumption/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Xaml.Shapes;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace US_Energy_Consumption
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}

private Window m_window;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added US_Energy_Consumption/Assets/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions US_Energy_Consumption/Converter/AxisLabelConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using Microsoft.UI.Xaml.Data;
using Syncfusion.UI.Xaml.Charts;
using System;

namespace US_Energy_Consumption
{
public class AxisLabelConverter : IValueConverter
{
EnergyUtilityConsumption viewModel = new EnergyUtilityConsumption();
public object Convert(object value, Type targetType, object parameter, string language)
{
ChartAxisLabel chartAxisLabel = value as ChartAxisLabel;
if (viewModel != null && chartAxisLabel != null)
{
var label = double.Parse((string)chartAxisLabel.Content);
return label > 1000 ? (label / 1000).ToString() + "K" : chartAxisLabel.Content;

}
return string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

public class ToolTipConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if(value != null)
{
var segment = value as StackedAreaSegment;
if (segment != null)
{
var name =segment.Series.Name;
return "United States: " + name;
}
return value;
}

return string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

public class ToolTipXValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value != null && value is DateTime date)
{
var month = date.Date;
return month.ToString("MMMM-yyyy");
}

return string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

public class ToolTipYValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value != null && value is double val)
{
string yValue = val.ToString("###,###");
return yValue;
}

return string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}

public class FillConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value != null)
{
var segment = value as StackedAreaSegment;
if (segment != null)
{
return segment.Series.Fill;
}
return value;
}

return string.Empty;
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit 0021029

Please sign in to comment.