Browse Source

add LineChart example in XSSF

pull/20/head
Tony Qu 11 years ago
parent
commit
ad2881249f
  1. 21
      examples/NPOI.XSSF.Examples.2012.sln
  2. 67
      examples/xssf/LineChart/LineChart.csproj
  3. 67
      examples/xssf/LineChart/Program.cs
  4. 36
      examples/xssf/LineChart/Properties/AssemblyInfo.cs
  5. 7
      examples/xssf/ScatterChart/Program.cs

21
examples/NPOI.XSSF.Examples.2012.sln

@ -63,6 +63,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Basic", "Basic", "{CD941EF6
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Chart", "Chart", "{8CFB89FD-C679-473B-B421-D7EC19D7FC4F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LineChart", "xssf\LineChart\LineChart.csproj", "{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -333,18 +335,29 @@ Global
{CFA33A5A-DA93-48BE-B513-6FCDA5447B9F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{CFA33A5A-DA93-48BE-B513-6FCDA5447B9F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CFA33A5A-DA93-48BE-B513-6FCDA5447B9F}.Release|x86.ActiveCfg = Release|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Debug|x86.ActiveCfg = Debug|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Release|Any CPU.Build.0 = Release|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BABCE350-9EC0-4EE7-A8E5-7CC73CA5E667} = {CD941EF6-8FB7-467D-8AE7-0C85E07BD53F}
{AFBE86E3-EDBE-45B4-8950-8B883102A47F} = {CD941EF6-8FB7-467D-8AE7-0C85E07BD53F}
{A1C0DE12-A626-431F-B2E1-DB4B3A706383} = {219097C8-95A0-479C-A713-8D4EB842C2FF}
{AAAED0B0-1797-464C-8DF6-96DEBFB57DE7} = {219097C8-95A0-479C-A713-8D4EB842C2FF}
{A3103D4C-7334-4B70-9524-E57105EB5E55} = {219097C8-95A0-479C-A713-8D4EB842C2FF}
{A1C0DE12-A626-431F-B2E1-DB4B3A706383} = {219097C8-95A0-479C-A713-8D4EB842C2FF}
{421AEE65-B2DB-4633-A5E1-97E9DC809ADE} = {8CFB89FD-C679-473B-B421-D7EC19D7FC4F}
{A429FB81-425D-4046-92B5-CBE0FBC9AA3F} = {8CFB89FD-C679-473B-B421-D7EC19D7FC4F}
{87009589-28B8-4F63-A50D-A0C599E01A1E} = {FB96FC42-FB38-4F3B-9BA2-ACE24653CE0D}
{ED6DC363-2017-4004-AF44-2AA171709EFC} = {FB96FC42-FB38-4F3B-9BA2-ACE24653CE0D}
{AFBE86E3-EDBE-45B4-8950-8B883102A47F} = {CD941EF6-8FB7-467D-8AE7-0C85E07BD53F}
{BABCE350-9EC0-4EE7-A8E5-7CC73CA5E667} = {CD941EF6-8FB7-467D-8AE7-0C85E07BD53F}
{421AEE65-B2DB-4633-A5E1-97E9DC809ADE} = {8CFB89FD-C679-473B-B421-D7EC19D7FC4F}
EndGlobalSection
EndGlobal

67
examples/xssf/LineChart/LineChart.csproj

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A429FB81-425D-4046-92B5-CBE0FBC9AA3F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LineChart</RootNamespace>
<AssemblyName>LineChart</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NPOI">
<HintPath>..\..\..\solution\Lib\NPOI.dll</HintPath>
</Reference>
<Reference Include="NPOI.OOXML">
<HintPath>..\..\..\solution\Lib\NPOI.OOXML.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXml4Net">
<HintPath>..\..\..\solution\Lib\NPOI.OpenXml4Net.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXmlFormats">
<HintPath>..\..\..\solution\Lib\NPOI.OpenXmlFormats.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

67
examples/xssf/LineChart/Program.cs

@ -0,0 +1,67 @@
using NPOI.SS.UserModel;
using NPOI.SS.UserModel.Charts;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace LineChart
{
class Program
{
static void Main(string[] args)
{
IWorkbook wb = new XSSFWorkbook();
ISheet sheet = wb.CreateSheet("linechart");
int NUM_OF_ROWS = 3;
int NUM_OF_COLUMNS = 10;
// Create a row and put some cells in it. Rows are 0 based.
IRow row;
ICell cell;
for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++)
{
row = sheet.CreateRow((short)rowIndex);
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++)
{
cell = row.CreateCell((short)colIndex);
cell.SetCellValue(colIndex * (rowIndex + 1));
}
}
IDrawing drawing = sheet.CreateDrawingPatriarch();
IClientAnchor anchor = drawing.CreateAnchor(0, 0, 0, 0, 0, 5, 10, 15);
IChart chart = drawing.CreateChart(anchor);
IChartLegend legend = chart.GetOrCreateLegend();
legend.Position = LegendPosition.TopRight;
ILineChartData<double, double> data = chart.GetChartDataFactory().CreateLineChartData<double, double>();
// Use a category axis for the bottom axis.
IChartAxis bottomAxis = chart.GetChartAxisFactory().CreateCategoryAxis(AxisPosition.Bottom);
IValueAxis leftAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Left);
leftAxis.SetCrosses(AxisCrosses.AutoZero);
IChartDataSource<double> xs = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
IChartDataSource<double> ys1 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));
IChartDataSource<double> ys2 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));
var s1 = data.AddSerie(xs, ys1);
s1.SetTitle("title1");
var s2 = data.AddSerie(xs, ys2);
s2.SetTitle("title2");
chart.Plot(data, bottomAxis, leftAxis);
using (FileStream fs =File.Create("test.xlsx"))
{
wb.Write(fs);
}
}
}
}

36
examples/xssf/LineChart/Properties/AssemblyInfo.cs

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LineChart")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LineChart")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("fe9a40ad-670a-4813-9b3a-0791300c2f9f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

7
examples/xssf/ScatterChart/Program.cs

@ -50,9 +50,10 @@ namespace ScatterChart
IChartDataSource<double> ys2 = DataSources.FromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));
data.AddSerie(xs, ys1);
data.AddSerie(xs, ys2);
var s1 = data.AddSerie(xs, ys1);
s1.SetTitle("title1");
var s2 = data.AddSerie(xs, ys2);
s2.SetTitle("title2");
chart.Plot(data, bottomAxis, leftAxis);
// Write the output to a file

Loading…
Cancel
Save