⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.cpp

📁 利用VC++开发的OCX控件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
										pDC->TextOut(xApexPoint - (xAxisWidth / 2) - (xAxisLabelLength * charWidth) - 5, tickYLocation - (tm.tmHeight / 2), tickLabel);
									}
									topYTick = tickYLocation;
									pDC->SelectObject(pOldFont);
								}
								topYTick = tickYLocation;
								pDC->SelectObject(pOldFont);
							}
							else
							{
								//scatter graphs will use the same tick marking on both axis lines
								int oldNumTicks;
								oldNumTicks = numTicks;
								numTicks /= 2;

								for(y = 0; y <= numTicks; y++)  
								{
									tickScale = (yAxisHeight - 10) / numTicks;
									tickYLocation = yApexPoint - (int)(y * tickScale);

									//draw tick mark
									pDC->MoveTo(xApexPoint - 3, tickYLocation);
									pDC->LineTo(xApexPoint + 3, tickYLocation);

									if(!inRedraw)
									{
										//draw tick label
										CString tickLabel;
										tickLabel.Format("%d", (y * tickSpace));

										CFont yFont;
										yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&yFont);

										pDC->TextOut(xApexPoint - (xAxisWidth / 2) - (tickLabel.GetLength() * (yTickFontSize / 2)) - 6, tickYLocation - 6, tickLabel);
									}
									topYTick = tickYLocation;
									pDC->SelectObject(pOldFont);
								}
								numTicks = oldNumTicks;
							}

							//draw X axis tick marks
							tickScale = (xAxisWidth - 10) / numTicks;
							for(x = 0; x <= numTicks / 2; x++)
							{
								tickXLocation = xApexPoint - (xAxisWidth / 2) + (int)(x * tickScale) + 5;

								if(!inRedraw)
								{
									pDC->MoveTo(tickXLocation,yApexPoint - 3);
									pDC->LineTo(tickXLocation,yApexPoint + 3);

									if(graphHasGridLines)
									{
										//draw grid lines
										COLORREF gridLineColor;
										gridLineColor = DARK_GREY;
										CPen gridPen (PS_SOLID, 1, gridLineColor);
										CPen* pOldPen;
										pOldPen = pDC->SelectObject(&gridPen);
										pDC->MoveTo(tickXLocation, yApexPoint - yAxisHeight);
										pDC->LineTo(tickXLocation, yApexPoint);
										pDC->SelectObject(pOldPen);
									}

									//draw tick label
									CString tickLabel;
									tickLabel.Format("%d", minTick + (x * tickSpace));
									if(!xAxisAlign)  //horizontal
									{
										CFont xFont;
										xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&xFont);
										charWidth = tm.tmAveCharWidth;
										pDC->TextOut(tickXLocation - ((tickLabel.GetLength() * charWidth) / 2), yApexPoint + 8, tickLabel);
										pDC->SelectObject(pOldFont);
									}
									else
									{
										CFont sideFont2;
										sideFont2.CreateFont(xTickFontSize, 0, (xAxisAlign * 10), 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&sideFont2);
										pDC->GetTextMetrics(&tm);
										charWidth = tm.tmAveCharWidth;
										if(xAxisAlign < 180)
											pDC->TextOut(tickXLocation - 8, yApexPoint + 8 + (xAxisLabelLength * charWidth), tickLabel);
										else
											pDC->TextOut(tickXLocation + 2, yApexPoint + 8, tickLabel);

										pDC->SelectObject(pOldFont);
									}
								}
								rightXTick = tickXLocation;
							}
							//draw the 0 location
							tickXLocation = xApexPoint - (xAxisWidth / 2) + (int)(x * tickScale);
							if(!inRedraw)
							{
								//draw tick label
								if(!xAxisAlign)  //horizontal
								{
									CFont xFont;
									xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
										ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
										DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
									pDC->SelectObject(&xFont);
									charWidth = tm.tmAveCharWidth;
									pDC->TextOut(tickXLocation - (charWidth / 2), yApexPoint + 8, "0");
									pDC->SelectObject(pOldFont);
								}
								else
								{
									CFont sideFont2;
									sideFont2.CreateFont(xTickFontSize, 0, (xAxisAlign * 10), 0, 700, FALSE, FALSE, 0,
										ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
										DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
									pDC->SelectObject(&sideFont2);
									pDC->GetTextMetrics(&tm);
									charWidth = tm.tmAveCharWidth;
									if(xAxisAlign < 180)
										pDC->TextOut(tickXLocation - 8, yApexPoint + 8 + (xAxisLabelLength * charWidth), "0");
									else
										pDC->TextOut(tickXLocation + 2, yApexPoint + 8, "0");

									pDC->SelectObject(pOldFont);
								}
							}

							for(; x <= numTicks; x++)
							{
								tickXLocation = xApexPoint - (xAxisWidth / 2) + (int)(x * tickScale);

								pDC->MoveTo(tickXLocation,yApexPoint - 3);
								pDC->LineTo(tickXLocation,yApexPoint + 3);

								if(!inRedraw)
								{
									if(graphHasGridLines)
									{
										//draw grid lines
										COLORREF gridLineColor;
										gridLineColor = DARK_GREY;
										CPen gridPen (PS_SOLID, 1, gridLineColor);
										CPen* pOldPen;
										pOldPen = pDC->SelectObject(&gridPen);
										pDC->MoveTo(tickXLocation, yApexPoint - yAxisHeight);
										pDC->LineTo(tickXLocation, yApexPoint);
										pDC->SelectObject(pOldPen);
									}

									//draw tick label
									CString tickLabel;
									tickLabel.Format("%d", minTick + (x * tickSpace));
									if(!xAxisAlign)  //horizontal
									{
										CFont xFont;
										xFont.CreateFont(xTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&xFont);
										charWidth = tm.tmAveCharWidth;
										pDC->TextOut(tickXLocation - ((tickLabel.GetLength() * charWidth) / 2), yApexPoint + 8, tickLabel);
										pDC->SelectObject(pOldFont);
									}
									else
									{
										CFont sideFont2;
										sideFont2.CreateFont(xTickFontSize, 0, (xAxisAlign * 10), 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&sideFont2);
										pDC->GetTextMetrics(&tm);
										charWidth = tm.tmAveCharWidth;
										if(xAxisAlign < 180)
											pDC->TextOut(tickXLocation - 8, yApexPoint + 8 + (xAxisLabelLength * charWidth), tickLabel);
										else
											pDC->TextOut(tickXLocation + 2, yApexPoint + 8, tickLabel);

										pDC->SelectObject(pOldFont);
									}
								}
								rightXTick = tickXLocation;
							}
							break;
						case 3 :
							pDC->TextOut(10, yApexPoint - (axisYLabel.GetLength() / 2), axisXLabel);

							pDC->SelectObject(&axisFont);
							pDC->GetTextMetrics(&tm);
							charWidth = tm.tmAveCharWidth;
							labelHeight = tm.tmHeight + 10;
							if(axisYLabel.GetLength() == 0)
								labelHeight = 0;
							pDC->TextOut(xApexPoint + (xAxisWidth / 2) - ((axisXLabel.GetLength() / 2) * charWidth), maxHeight - 5 - 6, axisYLabel);
							
							pDC->SelectObject(pOldFont);

							//to allow scalability (height may be less than tickRange)
							tickScale = 0.00;
							seriesSpace = yAxisHeight / graphSeries->GetCount();

							//draw y axis ticks
							if(graphType != SCATTER_GRAPH)
							{
								tickScale = (yAxisHeight - 10) / seriesSize;
								POSITION pos;
								pos = graphSeries->GetHeadPosition();
								CGraphSeries* tmpSeries;
								for(y = 1; y <= graphSeries->GetCount() / 2; y++)  
								{
									tmpSeries = (CGraphSeries*)graphSeries->GetNext(pos);

									tickYLocation = yApexPoint - (yAxisHeight / 2) + ((y * seriesSpace) - (seriesSpace / 2));

									//draw tick mark
									pDC->MoveTo(xApexPoint - 3, tickYLocation);
									pDC->LineTo(xApexPoint + 3, tickYLocation);

									if(!inRedraw)
									{
										//draw tick label
										CString tickLabel;
										tickLabel = tmpSeries->GetLabel();

										CFont yFont;
										yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, FIXED_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&yFont);
										charWidth = tm.tmAveCharWidth;

										pDC->TextOut(xApexPoint - 5 - (tickLabel.GetLength() * (yTickFontSize / 2)), tickYLocation - 6, tickLabel);
									}
									topYTick = tickYLocation;
									pDC->SelectObject(pOldFont);
								}
								//draw the 0 location
								tmpSeries = (CGraphSeries*)graphSeries->GetNext(pos);
								tickYLocation = yApexPoint;
								//draw tick mark
								pDC->MoveTo(xApexPoint - 3, tickYLocation);
								pDC->LineTo(xApexPoint + 3, tickYLocation);

								if(!inRedraw)
								{
									//draw tick label
									CString tickLabel;
									tickLabel = tmpSeries->GetLabel();

									CFont yFont;
									yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
										ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
										DEFAULT_QUALITY, FIXED_PITCH | FF_ROMAN,"Arial");
									pDC->SelectObject(&yFont);
									charWidth = tm.tmAveCharWidth;

									pDC->TextOut(xApexPoint - 5 - (tickLabel.GetLength() * (yTickFontSize / 2)), tickYLocation - 6, tickLabel);
								}
								topYTick = tickYLocation;
								pDC->SelectObject(pOldFont);
								y++;

								for(; y <= graphSeries->GetCount(); y++)  
								{
									tmpSeries = (CGraphSeries*)graphSeries->GetNext(pos);

									tickYLocation = yApexPoint - (yAxisHeight / 2) + ((y * seriesSpace) - (seriesSpace / 2));

									//draw tick mark
									pDC->MoveTo(xApexPoint - 3, tickYLocation);
									pDC->LineTo(xApexPoint + 3, tickYLocation);

									if(!inRedraw)
									{
										//draw tick label
										CString tickLabel;
										tickLabel = tmpSeries->GetLabel();

										CFont yFont;
										yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, FIXED_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&yFont);
										charWidth = tm.tmAveCharWidth;

										pDC->TextOut(xApexPoint - 5 - (tickLabel.GetLength() * (yTickFontSize / 2)), tickYLocation - 6, tickLabel);
									}
									topYTick = tickYLocation;
									pDC->SelectObject(pOldFont);
								}
							}
							else
							{
								//scatter graphs will use the same tick marking on both axis lines
								for(y = 0; y < numTicks / 2; y++)  
								{
									tickScale = (yAxisHeight - 10) / numTicks;
									tickYLocation = yApexPoint - (yAxisHeight / 2) + (int)(y * tickScale) + 5;

									//draw tick mark
									pDC->MoveTo(xApexPoint - 3, tickYLocation);
									pDC->LineTo(xApexPoint + 3, tickYLocation);

									if(!inRedraw)
									{
										//draw tick label
										CString tickLabel;
										tickLabel.Format("%d", maxTick - (y * tickSpace));

										CFont yFont;
										yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&yFont);

										pDC->TextOut(xApexPoint - (tickLabel.GetLength() * (yTickFontSize / 2)) - 8, tickYLocation - 6, tickLabel);
										pDC->SelectObject(pOldFont);
									}
								}
								//draw the 0 location
								tickYLocation = yApexPoint;
								//draw tick mark
								pDC->MoveTo(xApexPoint - 3, tickYLocation);
								pDC->LineTo(xApexPoint + 3, tickYLocation);

								if(!inRedraw)
								{
									//draw tick label
									CFont yFont;
									yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
										ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
										DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
									pDC->SelectObject(&yFont);

									pDC->TextOut(xApexPoint - (yTickFontSize / 2) - 8, tickYLocation - 6, "0");
									pDC->SelectObject(pOldFont);
								}
								y++;

								for(; y <= numTicks; y++)  
								{
									tickScale = (yAxisHeight - 10) / numTicks;
									tickYLocation = yApexPoint - (yAxisHeight / 2) + (int)(y * tickScale) + 5;

									//draw tick mark
									pDC->MoveTo(xApexPoint - 3, tickYLocation);
									pDC->LineTo(xApexPoint + 3, tickYLocation);

									if(!inRedraw)
									{
										//draw tick label
										CString tickLabel;
										tickLabel.Format("%d", maxTick - (y * tickSpace));

										CFont yFont;
										yFont.CreateFont(yTickFontSize, 0, 0, 0, 700, FALSE, FALSE, 0,
											ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
											DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN,"Arial");
										pDC->SelectObject(&yFont);

										pDC->TextOut(xApexPoint - (tickLabel.GetLength() * (yTickFontSize / 2)) - 5, tickYLocation - 6, tickLabel);
										pDC->SelectObject(pOldFont);
									}
									topYTick = tickYLocation;
								}
							}

							//draw X axis tick marks
							int oldNumTicks;
							oldNumTicks = numTicks;
							numTicks /= 2;
							tickScale = (xAxisWidth - 10) / numTicks;

							for(x = 0; x <= numTicks; x++)
							{
								tickXLocation = xApexPoint + (int)(x * tickScale);

								if(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -