Asp.net use owc component drawing (line chart area chart column chart, etc)

Source: Internet
Author: User

Principle: owc is short for Office Web compent, Microsoft's Office Web component. It provides a flexible and basic mechanism for drawing images on the web. In an Intranet environment, if you can assume that the client has a specific browser and some powerful software (such as IE6 and Office 2000/XP/2003), you can use the office
Web components provide an Interactive Graphic development environment. In this mode, the client workstation will share a large proportion of the entire task. In theory, all the pictures that excel can do can be painted through owc.

Step 1: reference this component on your website.

Step 2: click "add reference" to bring up a window to add owc references. :


Step 3: Reference Microsoft. Office. InterOP. owc11 in the code.

Note: If the vs2010 compiler is used, right-click the reference attribute of owc11 after the reference is successful: In "Reference", right-click owc11, and click "attribute"
Embedded interoperability type: false


Code:

Front-end:

<Html
Xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: placeholder id = "placeholder1" runat = "server"> </ASP: placeholder>
</Div>
</Form>
</Body>
</Html>


Background:

Using
System;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. datavisualization. charting;
Using Microsoft. Office. InterOP. owc11;

Namespace Image
{
Public partial class image1: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
String strseriesname = "legend 1 ";

// Store data
String [] monnum = new string [12] {"1", "2", "3", "4", "5", "6", "7 ", "8", "9", "10", "11", "12 "};
String [] moncount = new string [12] {"100", "200", "250", "150", "300", "400", "220 ", "350", "200", "180", "120", "280 "};

// Specify a specific string for the X axis to display data
String strxdata = string. empty;
Foreach (string strdata in monnum)
{
Strxdata + = strdata + "\ t ";
}

// Specify a specific string for the Y axis
String strydata = string. empty;
Foreach (string strvalue in moncount)
{
Strydata + = strvalue + "\ t ";
}

// Create a chartspace to place the chart
Chartspace layspace = new chartspaceclass ();
// Add a chart to the chartspace object
Chchart insertchart = layspace. charts. Add (0 );
// Specify the drawing type, which can be obtained through the chartcharttypeenum enumerated Value
Insertchart. type = chartcharttypeenum. chcharttypearea; // Area Chart

// Specify whether a legend is required for a chart.
Insertchart. haslegend = false;

// Add a title for the icon
Insertchart. hastitle = true;
Insertchart. Title. Caption = "journal account ";

// Add an illustration for the X axis
Insertchart. Axes [0]. hastitle = true;
Insertchart. Axes [0]. Title. Caption = "";

// Add an illustration for the Y axis
Insertchart. Axes [1]. hastitle = true;
// Insertchart. Axes [1]. Scaling. splitminimum = 100;
Insertchart. Axes [1]. Title. Caption = "quantity ";

// Add a series
Insertchart. seriescollection. Add (0 );

// Specify the name of the series.
Insertchart. seriescollection [0]. setdata (chartdimensionsenum. chdimseriesnames, (INT) chartspecialperformancesenum. chdataliteral, strseriesname );
// Specify a category
Insertchart. seriescollection [0]. setdata (chartdimensionsenum. chdimcategories, (INT) chartspecialperformancesenum. chdataliteral, strxdata );
// Specify the value
Insertchart. seriescollection [0]. setdata (chartdimensionsenum. chdimvalues, (INT) chartspecialperformancesenum. chdataliteral, strydata );

// Output file
String strabsolutepath = server. mappath (".") + "\ showdata.gif ";
Layspace. exportpicture (strabsolutepath, "animated GIF", 400,250 );

String strrelativepath = "./showdata.gif ";

// Add the image to placeholder1 and display it on the page
String strimagetag = " ";

This. placeholder1.controls. Add (New literalcontrol (strimagetag ));

}
}
}


Effect:




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.