C# 使用OWC生成图表
最近做一个项目,按客户需求,需要生成一些报表,OWC是比较合适的组件. 1、如何安装OWC组件 OWC 是Office Web Compents的缩写,即Microsoft的Office Web组件,包含SpreadSheet组件、Chart组件、PioTable组件和Data Source组件。 只要装了 Office 办公软件 ,
最近做一个项目,按客户需求,需要生成一些报表,OWC是比较合适的组件.
1、如何安装OWC组件
OWC是Office Web Compents的缩写,即Microsoft的Office Web组件,包含SpreadSheet组件、Chart组件、PioTable组件和Data Source组件。
只要装了 Office 办公软件 ,在 C:/Program Files/MSECache/owc11_12 中会有一个安装文件: OWC11.msi (offic 2003)
2、安装完成后,新建一个工程,再添加引用...-->com--> Microsoft Office XP Web Components 在bin文件夹中:Interop.OWC10.dll
引用空间:using Microsoft.Office.Interop.Owc11;
private void MakeLineChart()
{
//Y坐标轴
string[] DataName = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
//第一条曲线的数据
int[] Data = { 0, 10, 20, 100, 40, 50, 60 };
//第二条曲线的数据
int[] Data1 = { 100, 50, 41, 86 };
//第三条曲线的数据
int[] Data2 = { 10, 50, 100, 30, 50, 60 };
string strValue1 = "";
string strValue = "";
string strValue2 = "";
string strCateory = "";
//循环取得数据并格式化为OWC10需要的格式,(加'/t')
for (int i = 0; i
{
strCateory += DataName[i] + '/t';
}
for (int i = 0; i
{
strValue += Data[i].ToString() + '/t';
}
for (int i = 0; i
{
strValue1 += Data1[i].ToString() + '/t';
}
for (int i = 0; i
{
strValue2 += Data2[i].ToString() + '/t';
}
OWC10.ChartSpaceClass mySpace = new OWC10.ChartSpaceClass();//创建ChartSpace对象来放置图表
OWC10.ChChart myChart = mySpace.Charts.Add(0);//在ChartSpace对象中添加图表,Add方法返回chart对象
myChart.Type = OWC10.ChartChartTypeEnum.chChartTypeColumnClustered;//指定图表的类型为线性图
myChart.HasLegend = true;//指定图表是否需要图例
myChart.HasTitle = true;//给定标题
myChart.Title.Caption = "交易曲线图"; //图表名称
//给定X/Y轴的图示说明
myChart.Axes[0].HasTitle = true;
myChart.Axes[0].Title.Caption = "数量"; //横轴名称
myChart.Axes[1].HasTitle = true;
myChart.Axes[1].Title.Caption = "日期"; //纵轴名称
//添加一个series(序列)
myChart.SeriesCollection.Add(0);
//给定series的名字
myChart.SeriesCollection[0].SetData(OWC10.ChartDimensionsEnum.chDimSeriesNames, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, "购买");
//给定series的分类
myChart.SeriesCollection[0].SetData(OWC10.ChartDimensionsEnum.chDimCategories, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strCateory);
//给定具体值
myChart.SeriesCollection[0].SetData(OWC10.ChartDimensionsEnum.chDimValues, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);
//添加一个series
myChart.SeriesCollection.Add(1);
//给定series的名字
myChart.SeriesCollection[1].SetData(OWC10.ChartDimensionsEnum.chDimSeriesNames, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, "出售");
//给定series的分类
myChart.SeriesCollection[1].SetData(OWC10.ChartDimensionsEnum.chDimCategories, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strCateory);
//给定具体值
myChart.SeriesCollection[1].SetData(OWC10.ChartDimensionsEnum.chDimValues, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strValue1);
//添加一个series
myChart.SeriesCollection.Add(2);
//给定series的名字
myChart.SeriesCollection[2].SetData(OWC10.ChartDimensionsEnum.chDimSeriesNames, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, "总成交");
//给定series的分类
myChart.SeriesCollection[2].SetData(OWC10.ChartDimensionsEnum.chDimCategories, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strCateory);
//给定具体值
myChart.SeriesCollection[2].SetData(OWC10.ChartDimensionsEnum.chDimValues, (int)OWC10.ChartSpecialDataSourcesEnum.chDataLiteral, strValue2);
//输出成GIF文件
string strAbsolutePath = (Server.MapPath(".")) + @"/Images/tempChart.gif";
Response.Write(strAbsolutePath);
mySpace.ExportPicture(strAbsolutePath, "GIF", 300, 300); //输出图表
//创建GIF文件的相对路径
string strRelativePath = "Images/tempChart.gif";
//把图片添加到Image
Image1.ImageUrl = strRelativePath;
}
//图表类型枚举
OWC11.ChartChartTypeEnum[] chartTypes = new OWC11.ChartChartTypeEnum[]{
ChartChartTypeEnum.chChartTypeColumnClustered,
ChartChartTypeEnum.chChartTypeColumn3D,
ChartChartTypeEnum.chChartTypeBarClustered,
ChartChartTypeEnum.chChartTypeBar3D,
ChartChartTypeEnum.chChartTypeArea,
ChartChartTypeEnum.chChartTypeArea3D,
ChartChartTypeEnum.chChartTypeDoughnut,
ChartChartTypeEnum.chChartTypeLineStacked,
ChartChartTypeEnum.chChartTypeLine3D,
ChartChartTypeEnum.chChartTypeLineMarkers,
ChartChartTypeEnum.chChartTypePie,
ChartChartTypeEnum.chChartTypePie3D,
ChartChartTypeEnum.chChartTypeRadarSmoothLine,
ChartChartTypeEnum.chChartTypeSmoothLine};
string[] chartTypesCh = new string[] { "垂直柱状统计图", "3D垂直柱状统计图", "水平柱状统计图", "3D水平柱状统计
图", "区域统计图", "3D区域统计图", "中空饼图", "折线统计图", "3D折线统计图", "折线带点统计图", "饼图", "3D饼图", "网状统计
图", "弧线统计图" };

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.
