In-depth introduction to the CChart daily course-the seventh lesson of the silk, Optimus Prime

Source: Internet
Author: User

In the last lesson, I was stupid enough to introduce how to draw a CChart pie chart. This lesson introduces the bar chart, which is also a widely used form of chart.

Follow the method in the first lesson to create a VC project Lesson07.

Similarly, we only need to modify the response routine of WM_CREATE, as shown below.

Case WM_CREATE: chartWnd. attach (hWnd, kTypeStem); {double pY [5]; pY [0] = 3.0; pY [1] = 5.0; pY [2] = 4.0; pY [3] = 2.0; chartWnd. getChart ()-> AddStems (pY, 4); chartWnd. getChart ()-> SetDataTitle ("agent a sales volume", 0);} break;

Add a sequence with AddStems.

Run the program and obtain the following image.

650) this. width = 650; "src =" http://img.blog.csdn.net/20130917204000156? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt =" SouthEast "/>

Next we add labels to each column. The response routine for modifying the WM_CREATE message is as follows.

Case WM_CREATE: chartWnd. attach (hWnd, kTypeStem); {double pY [5]; pY [0] = 3.0; pY [1] = 5.0; pY [2] = 4.0; pY [3] = 2.0; chartWnd. getChart ()-> AddStems (pY, 4); chartWnd. getChart ()-> SetDataTitle ("agent a sales volume", 0); chartWnd. getChart ()-> SetStemLabel (_ T ("first quarter"), 0); chartWnd. getChart ()-> SetStemLabel (_ T ("second quarter"), 1); chartWnd. getChart ()-> SetStemLabel (_ T ("three quarters"), 2); chartWnd. getChart ()-> SetStemLabel (_ T (""), 3);} break;

You can use SetStemLabel to modify the label of a column.

Running result.

650) this. width = 650; "src =" http://img.blog.csdn.net/20130917204135031? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt =" SouthEast "/>

Only one sequence is drawn. CChart supports drawing multiple sequences in a bar chart. The method for adding a new sequence is the same.

Next, modify the response routine of WM_CREATE.

Case WM_CREATE: chartWnd. attach (hWnd, kTypeStem); {double pY [5]; pY [0] = 3.0; pY [1] = 5.0; pY [2] = 4.0; pY [3] = 2.0; chartWnd. getChart ()-> AddStems (pY, 4); chartWnd. getChart ()-> SetDataTitle ("agent a sales volume", 0); chartWnd. getChart ()-> SetStemLabel (_ T ("first quarter"), 0); chartWnd. getChart ()-> SetStemLabel (_ T ("second quarter"), 1); chartWnd. getChart ()-> SetStemLabel (_ T ("three quarters"), 2); chartWnd. getChart ()-> SetStemLabel (_ T (""), 3); pY [0] = 4.0; pY [1] = 1.0; pY [2] = 6.0; pY [3] = 3.0; chartWnd. getChart ()-> AddStems (pY, 4); chartWnd. getChart ()-> SetDataTitle ("Agent B sales", 1);} break;

Running effect.

650) this. width = 650; "src =" http://img.blog.csdn.net/20130917204311500? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt =" SouthEast "/>

Finally, we add a title to the bar chart.

In the previous break; insert a row before a row.

ChartWnd. GetChart ()-> SetTitle (_ T ("Agent Sales "));
Effect.

650) this. width = 650; "src =" http://img.blog.csdn.net/20130917204404203? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt =" SouthEast "/>

Move the mouse and you will find that the bar chart also has an interactive function.

This lesson is also very simple, and now the class is over.

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.