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.