First, add the MSCHART menu in the project -> Project-> add to project-> Components and controls-> registered activex controls-> Microsoft Chart Control, Version 6.0 (OLEDB)
Second, add CMSCHART M_CHART in CDEMOView
Third, create and set M_Chart
3.1 Creating CMSCHART // CDemoview :: OnCreate () Cremoview :: OnCreate () Crect Rc; GetClientRect (& RC); if (! M_chart ", WS_CHILD | WS_VISIBLE, RC, THIS, 10)) RETURN -1;
3.2 Adjust the size of the M_Chart in OnSize so that the change can vary from the window size to change // cdemoview :: Onsize if (m_chart.getsafehwnd ()) m_chart.movewindow (0, 0, cx, cy);
3.3 Set m_chartvoid cdemoview :: initchart () {// Setting Title M_CHART.SETTITLETEXT ("Mschart Sample By Thinkry@263.net");
// The following two sentences change the background color m_chart.getBackDrop (). GetFill (). SetStyle (1); m_chart.getBackDrop (). GetFill (). GetBrush (). Getfillcolor (). Set (255, 255555);
// Display legend m_chart.setshowlegend (true); m_chart.setColumn (1); m_chart.setColumnLabel (LPCTSTSTSTCOLUMN (2); m_chart.setColumnlabel ((lpctstr) "2 machine "); M_chart.setColumn (3); m_chart.setColumnlabel (LPCTSTR)" No. 3 ");
/ / Stack mode // m_chart.setstacking (true);
// Y axis sets Variant var; m_chart.get (). Getaxis (1, var) .GetValeScale (). SetAuto (false); // does not automatically launch Y-axis scale m_chart.getPlot (). Getaxis (1, var) .GetValeScale (). SetMaximum (100); // Y axis maximum scale m_chart.getplot (). Getaxis (1, var) .Getvaluescale (). Setminimum (0); // Y axis minimum scale m_Chart.getPlot (). GetAxis (1, var) .Getvaluescale (). SetmajordiVision (5); // Y-axis scale 5 equivalent m_chart.getPlot (). Getaxis (1, var) .GetValeScale (). SetminordiVision (1); // Each scale A tick m_chart.getPlot (). Getaxis (1, var) .Getaxistute (). SetText ("hour"); // y-axis name
// 3 curve M_Chart.SetColumnCount (3);
// Line color m_chart.getPlot (). GetSeriesCollection (). GetItem (1) .Getpen (). GetVtcolor (). Set (0, 0, 255); m_chart.getplot (). GetSeriesCollection (). GetItem (2) . GetPen (). GetVtcolor (). Set (255, 0, 0); m_chart.getplot (). GetSeriesCollection (). GetItem (3) .Getpen (). GetVtcolor (). Set (0, 255, 0); // Line width (valid to the point map) m_chart.getPlot (). GetSeriesCollection (). GetItem (1) .Getpen (). SetWidth (50); m_chart.getplot (). GetSeriesCollection (). GetItem (2). Getpen (). Setwidth (100); m_chart.get (). GetSeriescollection (). GetItem (3) .Getpen (). Setwidth (2);
// Data point type Displays the mode of the data value (valid to the column chart and point line diagram) // 0: Do not display 1: Displayed in the histogram // 2: Displayed in the histogram 3: display in the histogram Inner Middle 4: Displayed in the column map m_chart.getPlot (). GetSeriesCollection (). GetItem (1) .GetdataPoints (). GetItem (-1) .GetdataPointLabel (). SetLocationType (1); m_chart.getPlot (). GetSeriesCollection (). GetItem (2) .GetdataPoints (). GetItem (-1) .GetdataPointLabel (). SetLocationType (1); m_chart.getPlot (). GetSeriesCollection (). GetItem (3) .GetdataPoints (). GetItem (-) 1) .GetdataPointLabel (). SetLocationType (1);
3.4 Setting Data Void CDemoview :: Drawchart () {int nrowcount = 6; m_chart.setrowcount (nRowcount);
Variant var; m_chart.get (). Getaxis (0, var) .GetcategoryScale (). SetAuto (false); // does not automatically annotate x-axis scale m_chart.getPlot (). Getaxis (0, var) .getcategoryScale (). SetDivisionsperlabel (1); // A label M_Chart.get (). Getaxis (0, var) .GetcategorySpers (1); // each scale M_Chart.getPlot (). Getaxis (0, VAR) .GetaXistry (). setText ("Date"); // X axis name
Char BUF [32]; SRAND (NULL);
For (int ROW = 1; ROW <= nrowcount; row) {m_chart.setrow (row); sprintf (buf, "% number D", ROW);
M_Chart.seRowLabel ((LPCTSTR) BUF); m_chart.getdataGrid (). set, 1, rand () * 100 / rand_max, 0); m_chart.getdataGrid (). setData (row, 2, rand () * 100 / Rand_max, 0); m_chart.getdataGrid (). Setdata (row, 3, rand () * 100 / rand_max, 0);} m_chart.refresh ();}
3.5 Changing the display type
// Pacing chart void cdemoview :: onchartline () {m_chart.setcharttype (3); Drawchart ();
{M_chart.setchartType (1); Drawchart (); Drawchart ();
// Pie Void CDemoview :: OnChartpie () {m_chart.setcharttype (14); Drawchart ();