티스토리 뷰


구현 뭐 어려운 건 없다...

데이터 추가해서 보여주는 사이즈랑 비교해서 있는지 없는지...

출력하는 것은 2번 글에서 사용한 한줄로 간단하게 끝낼수도 있고...

꾸미려고 한다면 더 많이 꾸며야겠지만..

구현하면서 수정한 사항...

- LogData는 많은 데이터를 가지고 있는건데 하나만 보여주면 되니까 float로 수정..

- X의 min max는 필요 없더만.. 삭제..

- Polyline의 두번째 인자는 '선'의 수이므로, size - 1 로 수정


뭐, 나중에 동시에 여러 개를 동적으로 보여주려면 다시 LogData로 수정하면 될듯..

일단 동적 그래프부터 그리고 추가하도록 하자..



// 데이터를 추가하는 함수
int CAnimatedGraph::AddData(float data)
{ int nYWidth = this->m_rectGraphArea.bottom - this->m_rectGraphArea.top;
 int nXWidth = this->m_rectGraphArea.right - this->m_rectGraphArea.left;
 int nXDerivation = (int)(nXWidth / this->m_nViewDataSize);
 int nXCoordinate = this->m_rectGraphArea.right - nXDerivation;
 int nYCoordinate = (int)(this->m_rectGraphArea.bottom - ((this->m_fYMax - data) / (this->m_fYMax - this->m_fYMin)) * nYWidth);
//시간의 흐름
 for(int loop = 0 ; loop < (int)this->m_arrPoints.GetSize() ; loop++)
 {
  this->m_arrPoints.GetAt(loop).x = this->m_arrPoints.GetAt(loop).x - nXDerivation;
 }

 this->m_arrLogData.Add(data);        //데이터 추가
 this->m_arrPoints.Add(CPoint(nXCoordinate , nYCoordinate)); //점 추가
 
 
 if((int)this->m_arrLogData.GetSize() > this->m_nViewDataSize)
 {
  this->m_arrLogData.RemoveAt(0 , 1);
  this->m_arrPoints.RemoveAt(0 , 1);
 }
 return 0;
}

// 그리기 함수
int CAnimatedGraph::Draw(CDC* pDC)
{
 pDC->Rectangle(&this->m_rectGraphArea);
 pDC->Polyline(this->m_arrPoints.GetData() , (int)this->m_arrPoints.GetSize() - 1);
 return 0;
}



초간단하다... 나중에 멋드러지게 꾸미려면 Draw 함수를 수정하면 될것 같다.

이제 테스트를 들어가봐야겠다..


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함