我自己写的坐标图,可以定制坐标并切换,也可以用不同颜色画直线和曲线[2]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 workingon 的 blog

 // 显示背景虚线
 cpen newpen(ps_dot, 1, rgb(0, 0, 0));
 cpen* poldpen = pdc->selectobject(&newpen);
 for( i = 0; i < ny/10; i++)
 {
   cstring str;
   str.format("%3.1f",m_dorgy+i*m_ddivy*10);
   pdc->moveto(norgx, norgy - i*nmaxy/10);
   pdc->lineto(norgx + nmaxx, norgy - i*nmaxy/10);
   pdc->textout(norgx-50, norgy - i*nmaxy/10-4,str);

   for (int j=0;j<10;j++){
    cpen newpen(ps_solid, 1, rgb(0, 0, 0));
    cpen* poldpen = pdc->selectobject(&newpen);
    pdc->moveto(norgx,norgy - i*nmaxy/10-j*nmaxy/ny);
    if(j==5) {
     pdc->lineto(norgx+4+4,norgy - i*nmaxy/10-j*nmaxy/ny);
    }else{
    pdc->lineto(norgx+4,norgy - i*nmaxy/10-j*nmaxy/ny);
    }
    pdc->selectobject(poldpen);
   }
 }
 cstring str;str.format("%3.1f",i*m_ddivy*10);
 pdc->textout(norgx-50, norgy - i*nmaxy/10-4,str);

 for(i = 0; i < nx/10; i++)
 {
   cstring str;
   str.format("%3.1f",m_dorgx+i*m_ddivx*10);
   pdc->moveto(norgx + i*nmaxx/10, norgy);
   pdc->lineto(norgx + i*nmaxx/10, norgy - nmaxy);
   pdc->textout(norgx + i*nmaxx/10-8, norgy+4,str);

   for (int j=0;j<10;j++){
    cpen newpen(ps_solid, 1, rgb(0, 0, 0));
    cpen* poldpen = pdc->selectobject(&newpen);
    pdc->moveto(norgx + i*nmaxx/10+j*nmaxx/100,norgy);
    if(j==5){
     pdc->lineto(norgx + i*nmaxx/10+j*nmaxx/nx,norgy - 3 -3);
    }else{
    pdc->lineto(norgx + i*nmaxx/10+j*nmaxx/nx,norgy - 3);
    }
    pdc->selectobject(poldpen);
   }
 }
 str.format("%3.1f",m_dorgx+i*m_ddivx*10);
 pdc->textout(norgx + i*nmaxx/10-8, norgy+4,str);

 pdc->selectobject(poldpen);
 
 pdc->moveto(norgx, norgy);
 pdc->lineto(norgx, norgy - nmaxy);

 pdc->moveto(norgx + nmaxx, norgy);
 pdc->lineto(norgx + nmaxx, norgy - nmaxy);

 pdc->moveto(norgx, norgy);
 pdc->lineto(norgx + nmaxx, norgy);

 pdc->moveto(norgx, norgy - nmaxy);
 pdc->lineto(norgx + nmaxx, norgy - nmaxy);

 pdc->textout(norgx+nmaxx/2-10,norgy+20,m_pgstr->title);
 pdc->textout(norgx-10,norgy-nmaxy-20,m_pgstr->ystr);
 pdc->textout(norgx+nmaxx-60,norgy+20,m_pgstr->xstr);

 if(poldfnt!=null)
  pdc->selectobject(poldfnt);
}

void cgraph::onpaint()
{
 cpaintdc dc(this); // device context for painting
 
 // todo: add your message handler code here
 ondraw ();
 // do not call cwnd::onpaint() for painting messages
}

bool cgraph::create(lpctstr lpszclassname, lpctstr lpszwindowname, dword dwstyle, const rect& rect, cwnd* pparentwnd, uint nid, ccreatecontext* pcontext)
{
 return cwnd::create(afxregisterwndclass(cs_dblclks | cs_hredraw | cs_vredraw, null, (hbrush)(color_btnface+1),null),
      null,
      dwstyle,
      rect,
      pparentwnd,
      nid,
      pcontext);
}

void cgraph::settitle(int nindex)
{
 m_pgstr= &gstr[nindex];
}

void cgraph::setxscale(double dorgx, double dmaxx)
{
 m_dmaxx = dmaxx;
 m_dorgx = dorgx;
 m_ddivx = m_dmaxx / nx;
}
void cgraph::setyscale(double dorgy, double dmaxy)
{
 m_dmaxy = dmaxy;
 m_dorgy = dorgy;
 m_ddivy = m_dmaxy / ny;
}

void cgraph::drawpoint(double x, double y)
{
 crect rc;
 getclientrect(&rc);

 cdc *pdc=getdc();
 pdc->setmapmode(mm_anisotropic);
 pdc->setwindowext(640, 480);
 pdc->setviewportext(rc.right, rc.bottom);
 int tmpx,tmpy;

 tmpx = (int) (( x-m_dorgx) * maxx/m_dmaxx + orgx );
 tmpy = (int) ( orgy-(y-m_dorgy) * maxy/m_dmaxy  );

 pdc->moveto(tmpx-5,tmpy-5);
 pdc->setpixel(tmpx,tmpy,rgb(255,0,0));
}

本文关键:我自己写的坐标图,可以定制坐标并切换,也可以用不同颜色画直线和曲线
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top