(3) componentone's webchart (line chart) (sample code download)

Source: Internet
Author: User

Line chart
(1). Configuration

1. Install componentone software.

2. Create a web application project named Pie Chart

3. Copy the control set DLL file (not all, only part of the required file) that comes with componentone to the one you just created.

The bin directory of the Project textchart (the reason for this is that componentone sometimes cannot find the DLL)

4. Double-click any *. aspx file in the project to open the design interface. Open the toolbar, right-click in the blank area of the toolbar, and select "Add/Delete"

To open the custom control window, and select the corresponding componentone component under the. NET Frame Component tab,

Check all the items starting with C1 and click "OK". The componentone control is displayed in the toolbox.

5. In this step, you can drag and use the componentone control as a general control. Drag the c1webchart control

On the form page, right-click the control and select "chart wizard..." to set the display style (pie chart, bar chart, line chart, etc.) and

Attribute. The usage is similar to that of a common control. (In addition to using the designer settings, see the following (2)

You can also set it in code)

(2). Code Section

1. Implementation of line chart

Using c1.web. c1webchart; // namespace, which must be added; otherwise, the class and method in the namespace cannot be found.
Using c1.web. c1webchartbase;
Using c1.win. c1chart;

Protected c1.web. c1webchart. c1webchart c1webchart1; // control declaration

 

 

2. Main attributes

C1webchart1. header. Text = "chart Header"; // the title of the chart header.
C1webchart1. footer. Text = "chart end"; // chart end text
C1webchart1. backcolor = color. lightsteelblue; // background color
C1webchart1. imageformat = system. Drawing. imaging. imageformat. PNG; // Image Storage Format

C1webchart1. chartgroups. group0.charttype = chart2dtypeenum. xyplot; // chart

// Type. Some chart styles, such as pie charts and column charts, are enumerated in chart2dtypeenum.


C1webchart1. width = 800; // chart area width

3. Main method (the example line chart shows the Chinese, mathematics, and English scores of each student in a class ))

A. Call the X axis label (coordinate) method directly.

Public void addaxisx ()
{
// Label X axis with product names
Axis AX = c1webchart1. chartarea. axisx;
Ax. valuelabels. Clear ();
Ax. annomethod = annotationmethodenum. valuelabels;
For (INT I = 0; I <100; I ++)
{
// Datarowview DRV = DV [I];
Ax. valuelabels. Add (I, (I + 1). tostring ());
}
Try
{
Ax. max = 10-. 5;
}
Catch {}
}
B. Call the Y axis label (coordinate) method directly.

Public void addaxisy ()
{
// Label Y axis with product names
Axis ay = c1webchart1. chartarea. axisy;
Ay. valuelabels. Clear ();
Ay. annomethod = annotationmethodenum. valuelabels;
For (INT I = 0; I <10; I ++)
{
// Datarowview DRV = DV [I];
Ay. valuelabels. Add (I, (50 * I). tostring ());
}
Try
{
Ay. max = 20-. 5;
}
Catch {}
}

C. Core Method for drawing a line chart
Private void getline_plot () // fields are stored in DS: Chinese score/math score/English score/Name field.
{

// Line chart
// Clear the existing line chart
Chartdataseriescollection dscoll = c1webchart1. chartgroups [0]. chartdata. serieslist;
Dscoll. Clear ();

Int partition peratersnum = Ds. Tables [0]. Rows. count;
Pointf [] [] DATA = new pointf [3] [];

For (INT I = 0; I <3; I ++)
{
Data [I] = new pointf [intoperatersnum];
}

// Chinese score
For (INT I = 0; I <extends peratersnum; I ++)
{
Try
{
Float y = float. parse (Ds. Tables [0]. Rows [I] [""]). tostring ());
Data [0] [I] = new pointf (I, y );
}
Catch
{
Data [0] [I] = new pointf (I, 0 );
}
}

// Mathematical score
For (INT I = 0; I <extends peratersnum; I ++)
{
Try
{
Float y = float. parse (Ds. Tables [0]. Rows [I] [""]). tostring ());
Data [1] [I] = new pointf (I, y );
}
Catch
{
Data [1] [I] = new pointf (I, 0 );
}
}

// English score
For (INT I = 0; I <extends peratersnum; I ++)
{
Try
{
Float y = float. parse (Ds. Tables [0]. Rows [I] ["English score"]). tostring ());
Data [2] [I] = new pointf (I, y );
}
Catch
{
Data [2] [I] = new pointf (I, 0 );
}
}

For (INT I = 0; I <3; I ++)
{
Chartdataseries series = dscoll. addnewseries ();
Series. pointdata. Length = extends peratersnum;

Series. pointdata. copydatain (data [I]);
Series. linestyle. Thickness = 1; // Thickness
}
 
C1webchart1. chartgroups [0]. chartdata. serieslist [0]. Label = "Chinese score ";
C1webchart1. chartgroups [0]. chartdata. serieslist [1]. Label = "Mathematical score ";
C1webchart1. chartgroups [0]. chartdata. serieslist [2]. Label = "English score ";

C1webchart1. chartgroups [0]. chartdata. serieslist [0]. linestyle. Color = color. blue;
C1webchart1. chartgroups [0]. chartdata. serieslist [1]. linestyle. Color = color. Yellow;
C1webchart1. chartgroups [0]. chartdata. serieslist [2]. linestyle. Color = color. Red;

// Display name
Axis AX = c1webchart1. chartarea. axisx;
Ax. valuelabels. Clear ();
Ax. annomethod = annotationmethodenum. valuelabels;

For (INT I = 0; I <extends peratersnum; I ++)
{
Ax. valuelabels. Add (I, DS. Tables [0]. Rows [I] ["name"]. tostring ());
}
Try
{
// Ax. max = convert. tosingle (intpeoplenum-. 5 );
}
Catch {}
}

 

(3) various diagrams produced by componentonet

 

(4) Download Sample Code

Http://www.cnblogs.com/Files/ChengKing/C1WebChart2004.rar

 

 

 

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.