| |
 |
Convert Chart to Image with Image Options - Aspose.Cells
|
 |
This online demo demonstrates the ability of Aspose.Cells
for .NET to convert a chart to image file using different image options.
In this demo we ceate a chart using some static data.
Then different image options are applied like vertical and horizontal resolution of image, image format
and its TiffCompression etc.The chart is then converted to an image. You can either open the output
image file into your picture viewer or save directly to your disk.
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<%@ Page Language="VB" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" Inherits="Aspose.Cells.Demos.VisualBasic.Chart2ImageWithOptions"
Title="Convert Chart to Image with Image Options - Aspose.Cells Demos" Codebehind="chart-to-image-with-imageoptions.aspx.vb" %>
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" runat="Server">
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial"></span> </p>
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial"></span>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr>
<td valign="top" width="19">
<img alt="" height="41" src="/Common/images/heading_lft.jpg" width="19" /></td>
<td class="demos-heading-bg" width="100%">
<h2 class="demos-heading-bg">
<font face="Arial" size="4">Convert Chart to Image with Image Options - Aspose.Cells</font></h2>
</td>
<td valign="top" width="19">
<img alt="" height="41" src="/Common/images/heading_rt.jpg" width="19" /></td>
</tr>
</table>
</p>
<p class="componentdescriptiontxt">
<font face="Arial" size="2">This online demo demonstrates the ability of <a href="http://www.aspose.com/categories/file-format-components/aspose.cells-for-.net-and-java/default.aspx"
style="color: blue; text-decoration: underline; text-underline: single">Aspose.Cells</a>
for .NET to convert a chart to image file using different image options.</font></p>
<p class="componentdescriptiontxt">
<font face="Arial" size="2">In this demo we ceate a chart using some static data.
Then different image options are applied like vertical and horizontal resolution of image, image format
and its TiffCompression etc.The chart is then converted to an image. You can either open the output
image file into your picture viewer or save directly to your disk.
</font></p>
<p class="componentDescriptionTxt">
<asp:Button ID="btnExecute" runat="server" Text="Process" OnClick="btnExecute_Click"/> </p>
</asp:Content>
|
| Visual Basic |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
Imports System
Imports System.Data
Imports System.IO
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Aspose.Cells
Imports Aspose.Cells.Charts
Imports Aspose.Cells.Rendering
Partial Public Class Chart2ImageWithOptions
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub btnExecute_Click(ByVal sender As Object, ByVal e As EventArgs)
CreateStaticReport()
End Sub
Public Shared Sub CreateStaticReport()
'Create a new Workbook.
Dim workbook As New Workbook()
'Get the first worksheet.
Dim sheet As Worksheet = workbook.Worksheets(0)
'Set the name of worksheet
sheet.Name = "ChartSheet"
'Get the cells collection in the sheet.
Dim cells As Cells = workbook.Worksheets(0).Cells
'Put some values into different cells of the sheet.
cells("A1").PutValue("Region")
cells("A2").PutValue("France")
cells("A3").PutValue("Germany")
cells("A4").PutValue("England")
cells("A5").PutValue("Sweden")
cells("A6").PutValue("Italy")
cells("A7").PutValue("Spain")
cells("A8").PutValue("Portugal")
cells("B1").PutValue("Sale")
cells("B2").PutValue(70000)
cells("B3").PutValue(55000)
cells("B4").PutValue(30000)
cells("B5").PutValue(40000)
cells("B6").PutValue(35000)
cells("B7").PutValue(32000)
cells("B8").PutValue(10000)
'Create chart
Dim chartIndex As Integer = 0
chartIndex = sheet.Charts.Add(ChartType.Pie, 2, 4, 31, 15)
Dim chart As Chart = sheet.Charts(chartIndex)
'Set properties of chart title
chart.Title.Text = "Sales By Region"
chart.Title.TextFont.Color = System.Drawing.Color.Blue
chart.Title.TextFont.IsBold = True
chart.Title.TextFont.Size = 12
'Set properties of nseries
chart.NSeries.Add("B2:B8", True)
chart.NSeries.CategoryData = "A2:A8"
chart.NSeries.IsColorVaried = False
'Set the DataLabels in the chart
Dim datalabels As DataLabels
For i As Integer = 0 To chart.NSeries.Count - 1
datalabels = chart.NSeries(i).DataLabels
datalabels.Postion = LabelPositionType.Center
datalabels.IsCategoryNameShown = False
datalabels.IsValueShown = False
datalabels.IsPercentageShown = True
datalabels.IsLegendKeyShown = False
Next i
'Set the Legend.
Dim legend As Legend = chart.Legend
legend.Position = LegendPositionType.Left
'Apply different Image and Print options
Dim options As New ImageOrPrintOptions()
options.HorizontalResolution = 300
options.VerticalResolution = 300
options.TiffCompression = TiffCompression.CompressionLZW
options.IsCellAutoFit = False
options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff
options.PrintingPage = PrintingPageType.Default
'Create a memory stream object.
Dim ms As New MemoryStream()
'Conver the chart to image file.
chart.ToImage(ms, options)
'Set Response object to stream the image file.
Dim data() As Byte = ms.ToArray()
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "image/tiff"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ChartPic.tiff")
HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length)
'End response to avoid unneeded html after xls
HttpContext.Current.Response.End()
End Sub
End Class
|
|
|
|