首先下載mschart.ocx文件,至於它所依賴的.net環境,網上有很多,本人下載的插件給出鏈接,http://www.cr173.com/soft/47300.html而它所依賴的環境可以從我的雲盤中下載http://pan.baidu.com/s/1dETjpvj
安裝好后可以通過(1)regedit注冊表查看一下是否安裝成功。然后注冊插件:regsvr32 +path+mschart.ocx 注意:以管理員運行cmd。(2)還可以通過vs編譯器查看是否存在第三方插件:打開vs-->tool-->toolbox--->com。查找
勾選就可以在vs中使用該組件了。以上是mschart的安裝。下面來看一下qt環境下的demo.

1 /* 2 * @Time :2016.9.29 3 * @write by semon 4 * @顯示一個2d柱狀圖 5 */ 6 QAxWidget *widget = new QAxWidget(this); 7 widget->resize(size().width()-10,size().height()-10); 8 widget->setControl(QString::fromUtf8("{31291E80-728C-11CF-93D5-0020AF99504A}")); 9 10 pMsChart = new MsChart::_DMSChart(widget->asVariant().value<IDispatch*>()); 11 pMsChart->SetTitleText("MsChart`s example");//設置標題 12 //設置背景顏色 13 pMsChart->Backdrop()->Fill()->SetStyle(MsChart::VtFillStyleBrush); 14 pMsChart->Backdrop()->Fill()->Brush()->FillColor()->Set(120,120,120); 15 //設置SeriesType 16 pMsChart->setChartType(MsChart::VtChChartType3dArea);//餅圖 17 // pMsChart->SetSeriesType(MsChart::VtChSeriesType2dLine);//2dLine 18 pMsChart->SetColumnCount(3);//y軸三條曲線 19 pMsChart->SetRowCount(3);//x軸三條曲線 20 21 //顯示圖例 22 pMsChart->SetShowLegend(true); 23 pMsChart->SetColumn(1); 24 pMsChart->SetColumnLabel("1號機"); 25 pMsChart->SetColumn(2); 26 pMsChart->SetColumnLabel("2號機"); 27 pMsChart->SetColumn(3); 28 pMsChart->SetColumnLabel("3號機"); 29 //設置x軸 30 pMsChart->SetRow(1); 31 pMsChart->SetRowLabel("9.1"); 32 pMsChart->SetRow(2); 33 pMsChart->SetRowLabel("9.2"); 34 pMsChart->SetRow(3); 35 pMsChart->SetRowLabel("9.3"); 36 //棧模式 37 pMsChart->SetStacking(false); 38 //y軸設置 39 //不自動標注x/y軸刻度 40 //設置成true時 y軸會自動根據熟知的額多少對y軸最大值進行修改 41 pMsChart->Plot()->Axis(MsChart::VtChAxisIdY)->ValueScale()->SetAuto(false); 42 pMsChart->Plot()->Axis(MsChart::VtChAxisIdX)->ValueScale()->SetAuto(false); 43 44 //y軸最大/最小刻度 45 pMsChart->Plot()->Axis(MsChart::VtChAxisIdY)->ValueScale()->SetMaximum(200); 46 pMsChart->Plot()->Axis(MsChart::VtChAxisIdY)->ValueScale()->SetMinimum(0); 47 //y軸刻度等分 48 pMsChart->Plot()->Axis(MsChart::VtChAxisIdY)->ValueScale()->SetMajorDivision(5); 49 50 //每刻度一個刻度線 51 //y軸 52 pMsChart->Plot()->Axis(MsChart::VtChAxisIdY)->ValueScale()->SetMinorDivision(1); 53 //x軸 54 // pMsChart->Plot()->Axis(MsChart::VtChAxisIdX)->ValueScale()->SetMinorDivision(1); 55 56 //y軸名稱 57 pMsChart->Plot()->Axis(MsChart::VtChAxisIdY)->AxisTitle()->SetText("Hours"); 58 //x軸名稱 59 pMsChart->Plot()->Axis(MsChart::VtChAxisIdX)->AxisTitle()->SetText("Time"); 60 //y軸名稱的排列方式 61 pMsChart->Plot()->Axis(MsChart::VtChAxisIdY)->AxisTitle()->TextLayout()->Orientation(/*1*/); 62 //線色 63 pMsChart->Plot()->SeriesCollection()->Item(1)->Pen()->VtColor()->Set(0,0,255); 64 pMsChart->Plot()->SeriesCollection()->Item(2)->Pen()->VtColor()->Set(0,255,0); 65 pMsChart->Plot()->SeriesCollection()->Item(3)->Pen()->VtColor()->Set(255,0,0); 66 //線寬(對點位圖有效) 67 // pMsChart->Plot()->SeriesCollection()->Item(1)->Pen()->SetWidth(10); 68 // pMsChart->Plot()->SeriesCollection()->Item(2)->Pen()->SetWidth(20); 69 // pMsChart->Plot()->SeriesCollection()->Item(3)->Pen()->SetWidth(30); 70 //設置隱藏第二Y軸不可用 71 pMsChart->Plot()->Axis(MsChart::VtChAxisIdY2)->AxisScale()->SetHide(true); 72 //設置數值 73 pMsChart->DataGrid()->SetData(1,1,57,0); 74 pMsChart->DataGrid()->SetData(2,1,100,0); 75 pMsChart->DataGrid()->SetData(1,2,100,0); 76 //pMsChart->Plot()->SeriesCollection()->Item(1)->SetSecondaryAxis(false); 77 //數據點類型顯示數據值的模式(對柱狀圖和點線圖有效) 78 //0表示不顯示。1顯示柱狀圖。2顯示在柱狀圖內上方。3顯示在柱狀圖內中間。4顯示在柱狀圖內下方 79 pMsChart->Plot()->SeriesCollection()->Item(1)->DataPoints()->Item(-1)->DataPointLabel()->SetLocationType(MsChart::VtChLabelLocationTypeAbovePoint); 80 pMsChart->Plot()->SeriesCollection()->Item(2)->DataPoints()->Item(-1)->DataPointLabel()->SetLocationType(MsChart::VtChLabelLocationTypeAbovePoint); 81 pMsChart->Plot()->SeriesCollection()->Item(3)->DataPoints()->Item(-1)->DataPointLabel()->SetLocationType(MsChart::VtChLabelLocationTypeAbovePoint); 82 //不要與x軸垂直的表格線 83 pMsChart->Plot()->Axis(MsChart::VtChAxisIdX)->AxisGrid()->MajorPen()->SetStyle(MsChart::VtPenStyleNull); 84 85 pMsChart->Refresh();//更新插件
效果圖如下:
想要改變樣式:改變setChartType的值即可。
特別鳴謝:http://blog.csdn.net/u014023993/article/details/41542717