The project has a graphical requirement for reports, so it began to find a third-party chart control on the Internet. Due to time constraints, after several rounds of search in csdn, several candidates were identified: 1. owc control in office; 2. componentone; 3. Web chart.
Owc seems to be mostly used by many users, but some netizens complained in the post that owc needed a License book for use, so they excluded it, I don't want the boss to pop up a "no license book" window when reading the report.
Then we found the various types of componentone web charts, with excellent results. I was so fascinated by it that I decided to keep it. So I immediately went down to the installation file of the latest version of 100 m and found a usable registration code in the morning, and I found another tutorial, OK, everything is ready, and you are eager to start writing code. The requirement is not complex. Just draw multiple line charts on a single page. Based on past experience, this large commercial sharing software can definitely deal with two example on the official site for at most one hour. However, I am very annoyed by the results. The official example is simply not provided. What Ajax do you get and a lot of code to implement the auxiliary effect, the three or four lines of the core you are looking for cannot be found, as if you were afraid that you would suddenly understand its example. I have always hated such software. As a result, a day has passed.
Fortunately, I found the Web chart. The code is super concise and the effect is good. Write some simple examples for your reference:
I. line chart
// Reference the namespace
Using webchart;
// Define a color array to fill different colors for different records during the loop
Private string [] mycolor = new string []
{
"Tomato", // tomato
"Black ",
"Gold ",
"Blue ",
"Green ",
"Orange ",
"Pink", // pink
"Violet", // Violet
"Orchid", // lavender
"Lime", // bright green
"Tan", // Brown
"Red ",
"Navy" // orange
};
// The static method is used as an example to draw the simplest line of two points. The actual project loops accordingly.
Private void doit ()
{
// Create a line Object
Linechart MyChart = new linechart ();
// Fill the line color
MyChart. Line. Color = color. fromname (mycolor [0]);
MyChart. Fill. Color = color. fromname (mycolor [0]);
MyChart. linemarker = new diamondlinemarker (8, color. fromname (mycolor [0]), color. fromname (mycolor [0]);
// Legend
MyChart. Legend = "Line 1 ";
// Add the first vertex. Parameter 1 is the name of the X coordinate, and parameter 2 is the value of the Y coordinate.
MyChart. Data. Add (New chartpoint ("1", float. parse ("100 ")));
// Add the second Vertex
MyChart. Data. Add (New chartpoint ("2", float. parse ("200 ")));
// Chart is the Control ID.
This. Chart. charts. Add (MyChart );
This. Chart. redrawchart ();
}
Ii. Bar Chart
// Color array
Private string [] mycolor = new string []
{
"Fuchsia ",
"Black ",
"Gold ",
"Blue ",
"Hotpink ",
"Orange ",
"Peru ",
"Dodgerblue ",
"Lime ",
"Tan ",
"Red ",
"Greenyellow ",
"Darkgreen ",
"Dimgray ",
"Orchid"
};
// Call this method to generate a bar chart
Private void bindchart ()
{
// Obtain a datatable. The specific function is omitted...
Datatable dt = This. getdt ();
If (DT! = NULL)
{
If (Dt. Rows. Count> 0)
{
// Traverse the datatable to generate a column for each record
For (INT I = 0; I <DT. Rows. Count; I ++)
{
// Create an object
Columnchart MyChart = new columnchart ();
// Set the column width
MyChart. maxcolumnwidth = 48;
// Color
MyChart. Fill. Color = color. fromname (this. mycolor [I]);
// Display the quantity on the column
MyChart. datalabels. Visible = true;
// Number of fonts
MyChart. datalabels. font = new font ("verdana", 14 );
// Add
MyChart. Data. Add (New chartpoint ("", float. parse (Dt. Rows [I] ["num"]. tostring ())));
// Remarks
MyChart. Legend = DT. Rows [I] ["name"]. tostring ();
This. Chart. charts. Add (MyChart );
}
// Auxiliary settings
// Background color
Chart. Background. Color = color. fromargb (165, 0, 16 );
Chart. yaxisfont. forecolor = color. fromargb (165, 0, 16 );
Chart. xaxisfont. forecolor = color. fromargb (165, 0, 16 );
// Internal line
Chart. Border. Color = color. fromargb (200,200,200 );
// Border Style
Chart. borderstyle = borderstyle. None;
// Maximum value of Y
Double max = double. parse (Dt. Compute ("max (Num)", ""). tostring ());
// Increment Value
Int intv = 2;
// When the number is less than 16
If (max <16)
{
Max = 16;
}
// Case larger than 16
Else
{
Intv = int. parse (math. Ceiling (max/8). tostring ());
Max + = intv;
}
// Set the end value of the Y axis
Chart. ycustomend = int. parse (max. tostring ());
// Y increment Value
Chart. yvaluesinterval = intv;
// Generate
This. Chart. redrawchart ();
}
}
}
The Web chart is a free control. You can download it from the official address: http://www.carlosag.net/tools/webchart/default.aspx. there are also many effects and code examples.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/daisy_hui/archive/2007/03/01/1518283.aspx