-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from snehasf3509/master
Sample to create a chart and save as image
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Charts/Create-chart-and-save-as-image/.NET Standard/Create-chart-and-save-as-image.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.8.34322.80 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create-chart-and-save-as-image", "Create-chart-and-save-as-image\Create-chart-and-save-as-image.csproj", "{8182257B-E0CB-404F-A8ED-1DB1CB0CBBDF}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{8182257B-E0CB-404F-A8ED-1DB1CB0CBBDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8182257B-E0CB-404F-A8ED-1DB1CB0CBBDF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8182257B-E0CB-404F-A8ED-1DB1CB0CBBDF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8182257B-E0CB-404F-A8ED-1DB1CB0CBBDF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {6E30F48D-7BB4-4ED0-807A-70B73F82FBD4} | ||
EndGlobalSection | ||
EndGlobal |
15 changes: 15 additions & 0 deletions
15
...-image/.NET Standard/Create-chart-and-save-as-image/Create-chart-and-save-as-image.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Create_chart_and_save_as_image</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
49 changes: 49 additions & 0 deletions
49
...ts/Create-chart-and-save-as-image/.NET Standard/Create-chart-and-save-as-image/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Syncfusion.OfficeChart; | ||
using Syncfusion.Presentation; | ||
using Syncfusion.PresentationRenderer; | ||
|
||
|
||
//Creates a Presentation instance | ||
IPresentation pptxDoc = Presentation.Create(); | ||
//Adds a blank slide to the Presentation | ||
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); | ||
//Add a Pie chart | ||
IPresentationChart pieChart = CreatePieChart(slide); | ||
//Initialize the PresentationRenderer | ||
pptxDoc.PresentationRenderer = new PresentationRenderer(); | ||
// Converts the chart to image. | ||
Stream image = new FileStream("../../../ChartToImage.jpg", FileMode.Create, FileAccess.ReadWrite); | ||
pptxDoc.PresentationRenderer.ConvertToImage(pieChart, image); | ||
//Closes the presentation | ||
pptxDoc.Close(); | ||
image.Close(); | ||
|
||
IPresentationChart CreatePieChart(ISlide slide) | ||
{ | ||
//Adds chart to the slide with position and size | ||
IPresentationChart chart = slide.Charts.AddChart(100, 10, 500, 300); | ||
chart.ChartType = OfficeChartType.Pie; | ||
|
||
//Assign data | ||
chart.DataRange = chart.ChartData[2, 1, 6, 2]; | ||
chart.IsSeriesInRows = false; | ||
|
||
//Set data to the chart- RowIndex, columnIndex, and data | ||
chart.ChartData.SetValue(1, 1, "Food"); | ||
chart.ChartData.SetValue(2, 1, "Fruits"); | ||
chart.ChartData.SetValue(3, 1, "Vegetables"); | ||
chart.ChartData.SetValue(4, 1, "Dairy"); | ||
chart.ChartData.SetValue(5, 1, "Protein"); | ||
chart.ChartData.SetValue(6, 1, "Grains"); | ||
chart.ChartData.SetValue(1, 2, "Percentage"); | ||
chart.ChartData.SetValue(2, 2, 36); | ||
chart.ChartData.SetValue(3, 2, 14); | ||
chart.ChartData.SetValue(4, 2, 13); | ||
chart.ChartData.SetValue(5, 2, 28); | ||
chart.ChartData.SetValue(6, 2, 9); | ||
|
||
//Set Chart Title | ||
chart.ChartTitle = "Pie Chart"; | ||
|
||
return chart; | ||
} |