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

📄 bargraph3d.cs

📁 C#自定义查询控件
💻 CS
📖 第 1 页 / 共 2 页
字号:
						// Draw the ticker.
						this.DrawChartTicker(this.m_obGraphics, pt.X, pt.Y, nWidth, nHeight, 3,
							this.m_LegendsList[i], this.m_TickerTextDirection, this.GraphAlignment, this.m_TickColor);
					}

					// Draw Island legend.
					if (this.DrawXAxisLegend)
					{
						//dX = nStartX;
						//dY = (float)(nStartX + nIdx*(this.m_fIslandWidth + this.m_fIslandSpacing));
						dX = nStartX;
						dY = (float)(fStartY - nIdx*(this.m_fIslandWidth + this.m_fIslandSpacing));
						this.DrawIslandLegendText(m_obGraphics, this.m_XTickFont, dX, dY, this.m_fIslandDrawWidth,
							m_IslandLegendsList[nIdx], this.GraphAlignment, this.m_TickColor);
					}
				}
			}
			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawDataForHorizontalAlignment()
		{
			double dThickness = this.m_iYAxisSpan * m_fDepthFactor;
			int nHeight = 0;
			int nWidth = 0;
			int nLeftX = 0;
			int nLeftY = 0;
			double dX = 0.0;
			double dY = 0.0;
			int nStartX = (int)(this.m_ChartAxis.Origin.X + + m_fIslandSpacing/2.0F);

			for (int nIdx = 0; nIdx < this.m_obDataIslandNodes.Count; nIdx++)
			{
				ArrayList obIslandDataList = (ArrayList)this.m_obIslandList[nIdx];
				int nCount = obIslandDataList.Count;
				for (int i = 0; i < nCount; i++)
				{
					Color fillColor = (Color)this.m_arrColors[i];
					GraphDataObject obData = (GraphDataObject)obIslandDataList[i];
					if (null != obData)
					{
						// First draw the front rectangle.
						nHeight = (int)(obData.Y * this.m_dBarHeightScale);
						nWidth = (int)this.m_dDrawBarWidth;

						//nLeftX = (int)(this.m_ChartAxis.Origin.X + (i * this.m_dEqualBarWidth));
						nLeftX = (int)(nStartX + nIdx*(this.m_fIslandWidth + this.m_fIslandSpacing) + i * this.m_dEqualBarWidth);
						nLeftY = this.m_ChartAxis.Origin.Y - nHeight;
						this.DrawBar(this.m_obGraphics, nLeftX, nLeftY, nWidth, nHeight, dThickness, fillColor);

						// Draw the data value text.
						try
						{
							dX = nLeftX + dThickness;
							dY = nLeftY + nHeight - dThickness;
							this.DrawDataValue(this.m_obGraphics, this.m_YTickFont, dX, dY, nWidth, nHeight,
								obData.Y.ToString(), this.m_TickerTextDirection, this.GraphAlignment, this.m_TickColor, fillColor);
						}
						catch (Exception ex)
						{
							Trace.WriteLine(ex.Message);
						}

						// Draw the ticker.
						try
						{
							this.DrawChartTicker(this.m_obGraphics, nLeftX, nLeftY+nHeight, nWidth, nHeight, 3,
								this.m_LegendsList[i], this.m_TickerTextDirection, this.GraphAlignment, this.m_TickColor);
						}
						catch (Exception ex)
						{
							Trace.WriteLine(ex.Message);
						}
					}
				}
				// Draw Island legend.
				if (this.DrawXAxisLegend)
				{
					dX = (nStartX + nIdx*(this.m_fIslandWidth + this.m_fIslandSpacing));
					dY = this.m_ChartAxis.Origin.Y;
					this.DrawIslandLegendText(m_obGraphics, this.m_XTickFont, dX, dY, this.m_fIslandDrawWidth,
						m_IslandLegendsList[nIdx], this.GraphAlignment, this.m_TickColor);
				}
			}
			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawAxisForVerticalAlignment(bool bDrawGrid)
		{
			Pen obPen = null;
			Pen obGridPen = null;
			int iThickness = (int)(this.m_iYAxisSpan * m_fDepthFactor);
			Point x1, x11;
			Point x2, x22;
			Point y1, y11;
			Point y2, y22;
			try
			{
				x1 = new Point(this.m_ChartAxis.X1.X, this.m_ChartAxis.X1.Y);
				x2 = new Point(this.m_ChartAxis.X2.X, this.m_ChartAxis.X2.Y);
				y1 = new Point(this.m_ChartAxis.Y1.X, this.m_ChartAxis.Y1.Y);
				y2 = new Point(this.m_ChartAxis.Y2.X, this.m_ChartAxis.Y2.Y);

				obPen = new Pen(new SolidBrush(Color.Black));
				this.m_obGraphics.DrawLine(obPen, x1, x2);
				this.m_obGraphics.DrawLine(obPen, y1, y2);

				// Translate all four points to draw the axis at depth.
				x11 = x1 + new Size(iThickness, -iThickness);
				x22 = x2 + new Size(iThickness, -iThickness);
				y11 = y1 + new Size(iThickness, -iThickness);
				y22 = y2 + new Size(iThickness, -iThickness);

				string strVal = "";
				// Draw the grid lines now.
				if (HasGridLines && this.YTickSpacing > 0)
				{
					SizeF rectText;
					PointF pt1 = new PointF();
					PointF pt2 = new PointF();
					PointF pt3 = new PointF();
					PointF pt4 = new PointF();
					PointF pt5 = new PointF();
					PointF pt6 = new PointF();
					obGridPen = new Pen(GridColor);
					int iTickCount = (int)((this.MaxYValue - this.MinYValue)/this.YTickSpacing);
					float dYScale = (this.m_iYAxisSpan)/(float)(this.MaxYValue - this.MinYValue);
					float dXScale = (this.m_iXAxisSpan)/(float)(this.MaxYValue - this.MinYValue);
					for (int i = 0; i <= iTickCount; i++)
					{
						/*
						pt1.X = y2.X;
						pt1.Y = y2.Y - (i * this.YTickSpacing) * dYScale;

						pt2.X = pt1.X + iThickness;
						pt2.Y = pt1.Y - iThickness;

						pt3.X = pt2.X + this.m_iXAxisSpan;
						pt3.Y = pt2.Y;

						this.m_obGraphics.DrawLine(obGridPen, pt1, pt2);
						*/
						//this.m_obGraphics.DrawLine(obGridPen, pt2, pt3);
						pt4.X = x1.X + (i * this.YTickSpacing) * dXScale;
						pt4.Y = x1.Y;

						pt5.X = pt4.X + iThickness;
						pt5.Y = pt4.Y - iThickness;

						pt6.X = pt5.X;
						pt6.Y = pt5.Y - this.m_iYAxisSpan;

						this.m_obGraphics.DrawLine(obGridPen, pt4, pt5);
						this.m_obGraphics.DrawLine(obGridPen, pt5, pt6);

						Trace.WriteLine(pt4 + "," + pt5 + "," + pt6);

						strVal = (MinYValue + (i * YTickSpacing)).ToString();
						rectText = this.m_obGraphics.MeasureString(strVal, this.m_YTickFont);
						pt4.X = pt4.X - (rectText.Width/2.0F);
						this.m_obGraphics.DrawString(strVal, this.m_YTickFont, new SolidBrush(this.m_TitleColor), pt4);

					}
				}

				// Draw Rest of the lines.
				this.m_obGraphics.DrawRectangle(obPen, x11.X, y11.Y, this.m_iXAxisSpan, this.m_iYAxisSpan);
				this.m_obGraphics.DrawLine(obPen, y1, y11);
				this.m_obGraphics.DrawLine(obPen, y2, y22);
				this.m_obGraphics.DrawLine(obPen, x1, x11);
				this.m_obGraphics.DrawLine(obPen, x2, x22);
				this.m_obGraphics.DrawLine(obPen, x11, x22);
			}
			finally
			{
				if (obPen != null)
				{
					obPen.Dispose();
				}
			}
			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawAxisForHorizontalAlignment(bool bDrawGrid)
		{
			Pen obPen = null;
			Pen obGridPen = null;
			Pen obSubGridPen = null;
			int iThickness = (int)(this.m_iYAxisSpan * m_fDepthFactor);
			Point x1, x11;
			Point x2, x22;
			Point y1, y11;
			Point y2, y22;
			try
			{
				x1 = new Point(this.m_ChartAxis.X1.X, this.m_ChartAxis.X1.Y);
				x2 = new Point(this.m_ChartAxis.X2.X, this.m_ChartAxis.X2.Y);
				y1 = new Point(this.m_ChartAxis.Y1.X, this.m_ChartAxis.Y1.Y);
				y2 = new Point(this.m_ChartAxis.Y2.X, this.m_ChartAxis.Y2.Y);

				obGridPen = new Pen(GridColor);
				obGridPen.DashStyle = LineUtil.GetDashStyle(this.GridType);

				float diff = 0.0F;
				if (this.HasSubGridLines)
				{
					obSubGridPen = new Pen(SubGridColor);
					obSubGridPen.DashStyle = LineUtil.GetDashStyle(SubGridType);
				}

				obPen = new Pen(Color.Black);
				this.m_obGraphics.DrawLine(obPen, x1, x2);
				this.m_obGraphics.DrawLine(obPen, y1, y2);

				// Translate all four points to draw the axis at depth.
				x11 = x1 + new Size(iThickness, -iThickness);
				x22 = x2 + new Size(iThickness, -iThickness);
				y11 = y1 + new Size(iThickness, -iThickness);
				y22 = y2 + new Size(iThickness, -iThickness);

				string strVal = "";
				// Draw the grid lines now.
				if (this.YTickSpacing > 0)
				{
					SizeF rectText;
					PointF [] ptArr = new PointF[3];
					PointF [] ptArrSub = new PointF[3];
					PointF [] ptArrTemp = new PointF[3];
					PointF pt1 = new PointF();
					PointF pt2 = new PointF();
					PointF pt3 = new PointF();
					obGridPen = new Pen(GridColor);

					int iTickCount = (int)((this.MaxYValue - this.MinYValue)/this.YTickSpacing);
					float dYScale = (this.m_iYAxisSpan)/(float)(this.MaxYValue - this.MinYValue);
					float fYTickVal = this.YTickSpacing * dYScale;
					if (HasSubGridLines && bDrawGrid)
					{
						diff = fYTickVal/(SubGridLines+1);
					}
					for (int i = 0; i <= iTickCount; i++)
					{
						pt1.X = y2.X;
						pt1.Y = y2.Y - (i * this.YTickSpacing) * dYScale;

						pt2.X = pt1.X + iThickness;
						pt2.Y = pt1.Y - iThickness;

						pt3.X = pt2.X + this.m_iXAxisSpan;
						pt3.Y = pt2.Y;

						if (HasGridLines && bDrawGrid)
						{
							ptArr[0] = pt1;
							ptArr[1] = pt2;
							ptArr[2] = pt3;
							//this.m_obGraphics.DrawLine(obGridPen, pt1, pt2);
							//this.m_obGraphics.DrawLine(obGridPen, pt2, pt3);
							this.m_obGraphics.DrawLines(obGridPen, ptArr);
						}

						if (HasSubGridLines && bDrawGrid && SubGridLines > 0)
						{
							if (i > 0)
							{
								for (int k = 1; k <= this.SubGridLines; k++)
								{
									ptArrSub[0].X = ptArr[0].X; ptArrSub[0].Y = ptArr[0].Y + diff*k;
									ptArrSub[1].X = ptArr[1].X; ptArrSub[1].Y = ptArr[1].Y + diff*k;
									ptArrSub[2].X = ptArr[2].X; ptArrSub[2].Y = ptArr[2].Y + diff*k;

									this.m_obGraphics.DrawLines(obSubGridPen, ptArrSub);
								}
							}
						}

						//TODO: Parameterize tick size
						pt2.X = pt1.X - 3;
						pt2.Y = pt1.Y;
						this.m_obGraphics.DrawLine(obGridPen, pt1, pt2);

						strVal = (MinYValue + (i * YTickSpacing)).ToString();
						rectText = this.m_obGraphics.MeasureString(strVal, this.m_YTickFont);
						//TODO: Parameterize tick size
						pt1.X = pt1.X - 3 - (rectText.Width + 2);
						pt1.Y = pt1.Y - (rectText.Height/2.0F);
						this.m_obGraphics.DrawString(strVal, this.m_YTickFont, new SolidBrush(this.m_TitleColor), pt1);

					}
				}

				// Draw Rest of the lines.
				this.m_obGraphics.DrawRectangle(obPen, x11.X, y11.Y, this.m_iXAxisSpan, this.m_iYAxisSpan);
				this.m_obGraphics.DrawLine(obPen, y1, y11);
				this.m_obGraphics.DrawLine(obPen, y2, y22);
				this.m_obGraphics.DrawLine(obPen, x1, x11);
				this.m_obGraphics.DrawLine(obPen, x2, x22);
				this.m_obGraphics.DrawLine(obPen, x11, x22);
			}
			finally
			{
				if (obPen != null)
				{
					obPen.Dispose();
				}

				if (obGridPen != null)
				{
					obGridPen.Dispose();
				}

				if (obSubGridPen != null)
				{
					obPen.Dispose();
				}
			}
			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		override protected bool DrawAxisLabels()
		{
			/*
			try
			{
				// YAxis will be drawn vertical.
				StringFormat drawFormat = new StringFormat();
				drawFormat.FormatFlags = StringFormatFlags.DirectionVertical | StringFormatFlags.DirectionRightToLeft;

				this.m_obGraphics.DrawString(this.YAxisLabel, this.YAxisLabelFont, new SolidBrush(YAxisLabelColor), this.m_YAxisLabelLocation, drawFormat);
			}
			catch (Exception ex)
			{
				Trace.WriteLine(ex.Message);
				return false;
			}
			*/
			return true;
		}
	}
}

⌨️ 快捷键说明

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