(2) componentone's webchart (Bar Chart) (sample code download)

Source: Internet
Author: User

Bar Chart (the code example shows a complicated bar chart, and the running effect outline is displayed at the bottom)
(1). Configuration

1. Install componentone software.

2. Create a web application project named bar 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)

(2). Code Section (the example bar chart shows the Chinese, mathematics, and English scores of each student in a class ))
1. namespace and control declaration of the bar 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 of a bar chart
C1webchart1. header. Text = "2005 Class 5 score Chart display in Computer Science"; // 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. Bar; // chart
// Type. Some chart styles, such as pie charts and column charts, are enumerated in chart2dtypeenum.

C1webchart1. width = 800; // chart area width

3. Core Method of Bar Chart
Private void getbarchart (dataview DV) // DV is the passed data view, and the same is true if you use the dataset directly.
// DV has three columns: Chinese, mathematics, and English.
{

// Generate a 3D array point instance. Store the scores of each student in Chinese, mathematics, and English.
Pointf [] [] DATA = new pointf [3] [];
For (INT I = 0; I <3; I ++)
{
Data [I] = new pointf [DV. Count];
}

// Chinese score
For (INT I = 0; I <DV. Count; I ++)
{
Float y = float. parse (DV [I] [""]). tostring ());
Data [0] [I] = new pointf (I, y );
}

// Mathematical score
For (INT I = 0; I <DV. Count; I ++)
{
Float y = float. parse (DV [I] ["Mathematical score"]). tostring ());
Data [1] [I] = new pointf (I, y );
}

// English score
For (INT I = 0; I <DV. Count; I ++)
{
Float y = float. parse (DV [I] ["English score"]). tostring ());
Data [2] [I] = new pointf (I, y );
}

// Bind data
For (INT I = 0; I <3; I ++) // if it is a pair,
{
Chartdataseries series = c1webchart1. chartgroups [0]. chartdata. serieslist [I];

Series. pointdata. copydatain (data [I]); // The data here is of the pointf type
Series. fittype = c1.win. c1chart. fittypeenum. spline;
}

// Lend, description of bar blocks of three colors
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 ";



// Display the value in bar
Chartdataseriescollection dscoll = c1webchart1. chartgroups [0]. chartdata. serieslist;

C1webchart1. chartlabels. labelscollection. Clear ();
For (INT I = 0; I <dscoll. Count; I ++)
{
Chartdataseries series = dscoll [I];
For (Int J = 0; j <DV. Count; j ++)
{
// Add a label to display the score on the bar Block
C1.win. c1chart. Label LBL = c1webchart1. chartlabels. labelscollection. addnewlabel ();
If (I = 0 & Int. parse (DV [J] ["projectlastnum"]. tostring ())! = 0)
{
LBL. Text = string. Format ("{0}", Int. parse (DV [J] [""]. tostring ()));
}
If (I = 1 & Int. parse (DV [J] ["projectnormalnum"]. tostring ())! = 0)
{
LBL. Text = string. Format ("{0}", Int. parse (DV [J] [""]. tostring ()));
}
If (I = 2 & Int. parse (DV [J] ["projectbeyondnum"]. tostring ())! = 0)
{
LBL. Text = string. Format ("{0}", Int. parse (DV [J] ["English score"]. tostring ()));
}

LBL. Compass = labelcompassenum. South;
// LBL. style. backcolor = color. Brown;
LBL. style. forecolor = color. blue;
LBL. offset = 10;
LBL. Connected = false;
LBL. Visible = true;
LBL. attachmethod = attachmethodenum. dataindex;
Attachmethoddata AM = LBL. attachmethoddata;
// Am. groupindex = 0; // 0
// Am. seriesindex = 0; // I
// Am. pointindex = J; // 0
Am. groupindex = 0; // 0
Am. seriesindex = I; // I
Am. pointindex = J; // 0
}
}

// Display the X axis label
Axis AX = c1webchart1. chartarea. axisx;
Ax. valuelabels. Clear ();
Ax. annomethod = annotationmethodenum. valuelabels;

For (INT I = 0; I <DV. Count; I ++)
{
Ax. valuelabels. Add (I, DV [I] ["chiname"]. tostring ());
}
Try
{
// Ax. max = convert. tosingle (intpeoplenum-. 5 );
}
Catch {}
}

(3) various diagrams made with componentonet

 

(4). Sample download

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.