Microsoft Chart Control 6.0 (OLEDB) 是經典 ActiveX 圖表控件,本文給出 VC6/MFC 整合全流程與核心屬性配置代碼,涵蓋三種常用圖表類型切換。
CMSChart m_ChartOnCreate 中 m_Chart.Create("mschart", WS_CHILD|WS_VISIBLE, rect, this, 10)OnSize 中 m_Chart.MoveWindow(0,0,cx,cy) 實現自適應InitChart)SetTitleTextGetBackdrop().GetFill().SetStyle(1) + GetFillColor().Set(255,255,255)SetShowLegend(TRUE)SetColumnLabel 設「1號機/2號機/3號機」SetLocationType(1))DrawChart)SetRowLabel 設「1號」~「6號」GetDataGrid().SetData(row, col, rand()*100/RAND_MAX, 0)Refresh() 觸發重繪// 折線圖
m_Chart.SetChartType(3); DrawChart();
// 柱狀圖
m_Chart.SetChartType(1); DrawChart();
// 餅圖
m_Chart.SetChartType(14); DrawChart();
圖表類型常數:1=柱狀、3=折線、14=餅圖 (更多請查閱控件文檔)。範例編譯運行即見隨機生成的三系列圖表,菜單切換類型即時生效。