转载请注明出处!
1,添加ChartDirector中中的包括库
2,添加ChartDirector中中的LIB库
31,添加ChartDirector中中的LIB库
,
如图4所示,添加ChartViewer类。
5,添加声明#include “ChartViewer.h” 。
6.添加PICTURE控件,不需要变量,添加画2D图函数
void CChartDirectorDlg :: OnBnClickedBtnDraw()
{
// TODO:在此添加控件通知处理程序代码
double data0 [] = {42,49,33,38,51,46,29,41,44,57,59,52,37,34,51,56,56,60,70,
76,63,67,75,64,51};
// double data1 [] = {50,55,47,34,42,49,63,62,73,59,56,50,64,60,67,67,58,59,73,
// 77,84,82,80,84,98};
// double data2 [] = {36,28,25,33,38,20,22,30,25,33,30,24,28,15,21,26,46,42,48,
// 45,43,52,64,60,70};
//折线图的标签
const char * labels [] = {“0”,“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10 “” 11“” 12“ ,
“13”,“14”,“15”,“16”,“17”,“18”,“19”,“20”,“21”,“22”,“23”,“24”};
//创建一个尺寸为600 x 300像素的XYChart对象,背景为浅蓝色(EEEEFF),
//黑色边框,1个pxiel 3D边框效果和圆角
XYChart * c =新的XYChart(900,300,00eeeeff,0x000000,1);
C-> setRoundedFrame();
//将plotarea设置为(55,58),大小为520 x 195像素,白色背景。打开
//水平和垂直网格线,浅灰色(0xcccccc)
c-> setPlotArea(55,58,820,195,0xffffff,-1,-1,0xcccccc,0xcccccc);
//使用水平布局在(50,30)(图表顶部)添加图例框。使用9pt Arial Bold
//字体将背景和边框颜色设置为透明。
c-> addLegend(50,30,false,“arialbd.ttf”,9) - > setBackground(Chart :: Transparent);
//使用15pt Times Bold Italic字体在浅蓝色(CCCCFF)上为图表添加标题框
//背景与玻璃效果。暗红色(从0x800000)背景上的白色(0XFFFFFF),带有1
//像素3D边框。
c-> addTitle(“Application Server吞吐量”,“timesbi.ttf”,15) - > setBackground(0xccccff,
0x000000,Chart :: glassEffect());
//为ÿ轴添加标题
c-> yAxis() - > setTitle(“每小时MBytes”);
//在X轴上设置标签。
c-> xAxis() - > setLabels(StringArray(labels,(int)(sizeof(labels)/ sizeof(labels [0]))));
//在X轴上显示3个标签中的1个。
C-> x轴() - > setLabelStep(3);
//为X轴添加标题
c-> xAxis() - > setTitle(“2006年6月12日”);
//在图表中添加线图层
LineLayer * layer = c-> addLineLayer();
//将默认线宽设置为2像素
第一层> setLineWidth(2);
//将三个数据集添加到线图层。出于演示目的,我们使用虚线颜色
//最后一行
layer-> addDataSet(DoubleArray(data0,(int)(sizeof(data0)/ sizeof(data0 [0]))),0xff0000,
“服务器#1”);
// layer-> addDataSet(DoubleArray(data1,(int)(sizeof(data1)/ sizeof(data1 [0]))),0x008800,
//“服务器#2”);
// layer-> addDataSet(DoubleArray(data2,(int)(sizeof(data2)/ sizeof(data2 [0]))),c-> dashLineColor(
// 0x3333ff,Chart :: DashLine),“Server#3”);
//输出图表
C-> makeChart(“multiline.png”);
m_image.Destroy();
m_image.Load(_T(“multiline.png”));
CRect rectControl; //控件矩形对象
CRect rectPicture; //图片矩形对象
CWnd * pWnd = GetDlgItem(IDC_PIC);
pWnd-> GetClientRect(rectControl);
CDC * pDc = GetDlgItem(IDC_PIC) - > GetDC();
SetStretchBltMode(pDc-> m_hDC,STRETCH_HALFTONE);
rectPicture = CRect(rectControl.TopLeft(),CSize((int)rectControl.Width(),(int)rectControl.Height()));
((静态控件*)函数GetDlgItem(IDC_PIC)) - > SetBitmap(NULL);
m_image.Draw(pDc-> m_hDC,rectPicture);
pWnd-> ReleaseDC(PDC);
//释放资源
删除℃;
}
7.添加PICTURE控件,不需要变量,添加画3D图函数
void CChartDirectorDlg :: OnBnClickedBtnDraw3d()
{
// TODO:在此添加控件通知处理程序代码
CFileDialog fileDlg(TRUE,_T(“png”),NULL,0,_T(“图像文件(* .bmp; * .jpg; * .png)| * .JPG; * .PNG; * .BMP |所有文件(*。*)| *。* ||“),这个);
fileDlg.DoModal();
//获取图片路径和图片名称
CString strFilePath = fileDlg.GetPathName();
CString strFileName = fileDlg.GetFileName();
//判断路径不为空
if(strFilePath == _T(“”))
{
返回;
}
CImage m_Img;
m_Img.Destroy();
m_Img.Load(strFilePath);
/////////////////////////////
int w = m_Img.GetWidth();
int h = m_Img.GetHeight();
double * x = new double [w];
double * y = new double [h];
double * z = new double [w * h];
byte * pDataDst =(byte *)m_Img.GetBits(); //获取指向图像数据的指针
int pitchDst =(m_Img.GetPitch()); //获取每行图像占用的字节数+:自上而下; - :自下而上的DIB
int bitCountDst = m_Img.GetBPP()/ 8; //获取每个像素占用的字节数
for(int i = 0; 我<h; 我++)//行
{
y [i] = i;
for(int j = 0; j <w; j ++)//列
{
x [j] = j;
z [i * w + j] = *(pDataDst +((pitchDst <0)?(pitchDst *(h-1-i)):( pitchDst * i))+ j * bitCountDst);
}
}
SurfaceChart * c = new SurfaceChart(w,h / *,Chart :: brushedSilverColor(),0x888888 * /);
c-> setRoundedFrame(0xffffff,20,0,20,0);
c-> setPlotRegion(w / 2,5 * h / 10,0.8 * w,0.6 * h,600);
// c-> setPlotRegion(w / 2,h / 2,640,480,300);
//将高程和旋转角度设置为45和-45度
C-> setViewAngle(50,0);
//将透视级别设置为30
C->的的setPerspective(20);
c-> setInterpolation(40,40); // !!!
c-> setData(DoubleArray(x,w),DoubleArray(y,h),DoubleArray(z,w * h));
// c-> setData(DoubleArray(x,w),DoubleArray(y,h),DoubleArray(z,w * h));
//添加右上角锚定在(660,80)的颜色轴(图例)设置。
//长度为200像素,右侧为标签。
// ColorAxis * cAxis = c-> setColorAxis(w,80,Chart :: TopRight,350,Chart :: Right);
//将曲面网格线设置为半透明黑色(cc000000)
C-> setSurfaceAxisGrid(0xcc000000);
//将轮廓线设置为半透明白色(80ffffff)
C-> setContourColor(0x80ffffff);
//将墙壁设置为黑色
C-> setWallColor(0x000000处);
//将壁厚设置为0
c-> setWallThickness(0,0,0);
//仅显示XY墙,并隐藏YZ和ZX墙。
// c-> setWallVisibility(false,false,false);
c-> setWallVisibility(true,true,true);
c-> xAxis() - > setLinearScale(0,w,50);
c-> yAxis() - > setLinearScale(0,h,50);
c-> zAxis() - > setLinearScale(0,255,30);
//输出图表
C-> makeChart(“tem3d.png”);
// Mat m_3DImage = imread(“tem3d.png”);
//
// m_3DPic.SetImgInfo(m_3DImage);
m_image.Destroy();
m_image.Load(_T(“tem3d.png”));
CRect rectControl; //控件矩形对象
CRect rectPicture; //图片矩形对象
CWnd * pWnd = GetDlgItem(IDC_3DPIC);
pWnd-> GetClientRect(rectControl);
CDC * pDc = GetDlgItem(IDC_3DPIC) - > GetDC();
SetStretchBltMode(pDc-> m_hDC,STRETCH_HALFTONE);
rectPicture = CRect(rectControl.TopLeft(),CSize((int)rectControl.Width(),(int)rectControl.Height()));
((静态控件*)函数GetDlgItem(IDC_3DPIC)) - > SetBitmap(NULL);
m_image.Draw(pDc-> m_hDC,rectPicture);
pWnd-> ReleaseDC(PDC);
删除℃;
删除[] x;
删除[] y;
删除[] z;
}
8运行结果