C # Some personal experiences of drawing with ChartDirector

Source: Internet
Author: User

Introduction:
Recently, I made a big screen securities trading software with a B/S architecture for the customer, which is used to plot the trend of the securities index and the transaction volume, because the customer requires that the image be clear and the image display effect be the same as that of the original old system, it is very convenient to use ChartDirector to draw the image, CTrl + C and CTrl + V draw a trend chart, which looks similar to what the customer gave. It's quite simple. When you want to adjust the details, you can find that the desired results cannot be reached, then I searched the internet and found that some items were copied from the help document, and there were very few C # items, in the end, I tried the parameters with the help of Kingsoft word overlord in the case of VS smart prompts, and finally got the desired effect, the following describes the main code of the trend chart drawn by the individual (modified)

Code:

Using ChartDirector;

// Generate graphic data information, iWidth: width related to the canvas, iHeight: height related to the canvas, dlChartData: Y axis data
Private XYChart GetTrendChart (int iWidth, int iHeight, double [] dlChartData)
{
Try
{
/*********** The code here is for reference only. When a person draws the first vertex, the Code starts from the center of the Y axis, and the corresponding securities opening time is ******************/
Double dlLin = dlChartData [0];
Double dlMax = dlChartData [0];
// X axis data
String [] XData = new string [2880];
For (int I = 0; I <dlChartData. Length; I ++)
{
XData [I] = "";

// Obtain the minimum data
If (dlChartData [I] <dlLin)
DlLin = dlChartData [I];

// Obtain the maximum data
If (dlChartData [I]> dlMax)
DlMax = dlChartData [I];
}

// Continue to assign values to unassigned data
For (int I = dlChartData. Length; I <2880; I ++)
{
XData [I] = "";
}

// The floating size of the minimum and maximum values relative to the first Vertex
Double dlFir = Math. Abs (m_KPNum-dlLin );
Double dlSec = Math. Abs (m_KPNum-dlMax );
Double dlFloat = dlFir> dlSec? DlFir: dlSec;

/*************************************** *******/

******************** ***/

// Create a graphic object
XYChart c = new XYChart (iWidth, iHeight );

// Set the Y axis
Double dMin = Math. Round (m_KPNum-dlFloat, 2 );
Double dMax = Math. Round (m_KPNum + dlFloat, 2 );

If (dMax-dMin) <dlChartData [0] * 0.5)
{
DMax = Math. Round (dlChartData [0] + dlChartData [0] * 0.5, 2 );
DMin = Math. Round (dlChartData [0]-dlChartData [0] * 0.5, 2 );
}

// Set the value range of the Y axis
C. yAxis (). setDateScale (dMin, dMax );

// Set the number of gridlines to be displayed on the Y axis to 4.
C. yAxis (). setLinearScale (dMin, dMax, (dMax-dMin)/4 );

// C. yAxis (). setLabel (); the line layer cannot be automatically generated after the Label is set on the Y axis.
// C. yAxis (). setLabelGap (10); // you can specify the gap between labels on the Y axis.
// C. yAxis (). setLabelStep (int) (dMax-dMin)/10); // sets the display span of the Y axis label array.
// C. yAxis (). setLabelFormat ("{value} %"); // format the Label display content
/// Set the size of the area above the grid and below the title to (50, 30), horizontal word arrangement, font to, size to 9
// C. addLegend (50, 30, false, "Arial Bold", 9). setBackground (Chart. Transparent );


& N

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.