private void SetYAxis(ref Graphics objGraphics) { int x1 = 95; //int y1 = (int)(Height - 100 - 10 * (YSlice / 50)); int y1 = (int)(Height - BottomToXHeight - 10 * (YSlice / 50)); int x2 = 105; //int y2 = (int)(Height - 100 - 10 * (YSlice / 50)); int y2 = (int)(Height - BottomToXHeight - 10 * (YSlice / 50)); int iCount = 1; float Scale = 0; int iSliceCount = 1; int iHeight = (int)((Height - 200 - 100) * (50 / YSlice)); //objGraphics.DrawString(YSliceBegin.ToString(), new Font("宋体", 10), new SolidBrush(SliceTextColor), 60, Height - 110); objGraphics.DrawString(YSliceBegin.ToString(), new Font("宋体", 10), new SolidBrush(SliceTextColor), 60, Height - BottomToXHeight - 10); for (int i = 0; i < iHeight; i += 10) { Scale = i * (YSlice / 50); if (iCount == 5) { objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor)), x1 - 5, y1 - Scale, x2 + 5, y2 - Scale); //The Point这里显示Y轴刻度 objGraphics.DrawString(Convert.ToString(YSliceValue * iSliceCount + YSliceBegin), new Font("宋体", 10), new SolidBrush(SliceTextColor), 60, y1 - Scale); iCount = 0; iSliceCount++; } else { objGraphics.DrawLine(new Pen(new SolidBrush(SliceColor)), x1, y1 - Scale, x2, y2 - Scale); } iCount++; } }
/// <summary> /// 初始化Y轴上的刻度和文字 /// </summary> /// <param name="objGraphics"></param> private void SetYAxis(ref Graphics objGraphics) { if (!isYSliceSign) { return; } float fltX1 = XSpace; float fltY1 = Height - YSpace; float fltX2 = XSpace; float fltY2 = Height - YSpace; int iCount = 0; float Scale = 0; int iSliceCount = 1; float iWidth = ((Height - 2 * XSpace) / XSlice) * 50; //将要画刻度的长度分段,并乘以50,以10为单位画刻度线。 float fltSliceWidth = YSlice / 10; //刻度线的宽度 string strSliceText = string.Empty; objGraphics.TranslateTransform(XSpace - intFontSpace * YSliceBegin.ToString().Length, Height - YSpace); //平移图像(原点) objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); //旋转图像 objGraphics.DrawString(YSliceBegin.ToString(), new Font("楷体", FontSize), new SolidBrush(SliceTextColor), -6, -6); objGraphics.ResetTransform(); //重置图像 for (int i = 0; i < iWidth + 10; i += 10) { Scale = i * YSlice / 50; //即(i / 10) * (YSlice / 5),将每个刻度分五部分画,但因为i以10为单位,得除以10 if (iCount == 5) { objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor)), fltX1 - fltSliceWidth * 1.5f, fltY1 - Scale, fltX2 + fltSliceWidth * 1.5f, fltY2 - Scale); //画网格虚线 if (IsYSliceLine) { Pen penDashed = new Pen(new SolidBrush(AxisColor)); penDashed.DashStyle = DashStyle.Dash; objGraphics.DrawLine(penDashed, XSpace, fltY1 - Scale, (Width - XSpace + XSlice / 2) - 17, fltY2 - Scale); //为了缩短距离 -17 张祥明2013-03-13 } //这里显示Y轴刻度 strSliceText = Convert.ToString(YSliceValue * iSliceCount + YSliceBegin); objGraphics.TranslateTransform(XSpace - intFontSize * strSliceText.Length, fltY1 - Scale); //平移图像(原点) objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); //旋转图像 objGraphics.DrawString(strSliceText, new Font("楷体", FontSize), new SolidBrush(SliceTextColor), -6, -6); //默认为 0,0 (-5,8 为了将刻度数字下调) objGraphics.ResetTransform(); //重置图像 iCount = 0; iSliceCount++; if (fltX1 + Scale > Width - XSpace) { break; } } else { objGraphics.DrawLine(new Pen(new SolidBrush(SliceColor)), fltX1 - fltSliceWidth, fltY1 - Scale, fltX2 + fltSliceWidth, fltY2 - Scale); } iCount++; } }
/// <summary> /// 初始化Y轴上的刻度和文字 /// </summary> /// <param name="objGraphics"></param> private void SetYAxis(ref Graphics objGraphics) { try { float fltX1 = XSpace; float fltY1 = Height - YSpace; float fltX2 = XSpace; float fltY2 = Height - YSpace; int iCount = 0; float Scale = 0; int iSliceCount = 1; float iHeight = ((Height - 2 * YSpace) / YSlice) * 50; //将要画刻度的长度分段,并乘以50,以10为单位画刻度线。 float fltSliceWidth = YSlice / 10; //刻度线的宽度 string strSliceText = string.Empty; objGraphics.TranslateTransform(XSpace - intFontSpace * YSliceBegin.ToString().Length, Height - YSpace); //平移图像(原点) objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); //旋转图像 objGraphics.DrawString(YSliceBegin.ToString(), new Font("SimSun", FontSize), new SolidBrush(SliceTextColor), 0, 0); objGraphics.ResetTransform(); //重置图像 for (int i = 0; i < iHeight; i += 10) { Scale = i * YSlice / 50; //即(i / 10) * (YSlice / 5),将每个刻度分五部分画,但因为i以10为单位,得除以10 if (iCount == 5) { objGraphics.DrawLine(new Pen(new SolidBrush(AxisColor)), fltX1 - fltSliceWidth * 1.5f, fltY1 - Scale, fltX2 + fltSliceWidth * 1.5f, fltY2 - Scale); //画网格虚线 Pen penDashed = new Pen(new SolidBrush(AxisColor)); penDashed.DashStyle = DashStyle.Dash; objGraphics.DrawLine(penDashed, XSpace, fltY1 - Scale, Width - XSpace + XSlice / 2, fltY2 - Scale); //这里显示Y轴刻度 strSliceText = Convert.ToString(YSliceValue * iSliceCount + YSliceBegin); objGraphics.TranslateTransform(XSpace - intFontSize * strSliceText.Length, fltY1 - Scale); //平移图像(原点) objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); //旋转图像 objGraphics.DrawString(strSliceText, new Font("SimSun", FontSize), new SolidBrush(SliceTextColor), 0, 0); objGraphics.ResetTransform(); //重置图像 iCount = 0; iSliceCount++; } else { objGraphics.DrawLine(new Pen(new SolidBrush(SliceColor)), fltX1 - fltSliceWidth, fltY1 - Scale, fltX2 + fltSliceWidth, fltY2 - Scale); } iCount++; } } catch { } }
/// <summary> /// 初始化Y轴上的刻度和文字 /// </summary> /// <param name="objGraphics"></param> private void SetYAxis(ref Graphics objGraphics) { try { float fltX1 = XSpace; float fltY1 = Height - YSpace; float fltX2 = XSpace; float fltY2 = Height - YSpace; float Scale = 0; int iSliceCount = MinY; float iHeight = (Height - 2 * YSpace); //有效长度 objGraphics.TranslateTransform(XSpace - intFontSpace * YSliceBegin.ToString().Length, Height - YSpace); //平移图像(原点) objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); //旋转图像 objGraphics.DrawString(MinY.ToString(), new Font("SimSun", FontSize), new SolidBrush(SliceTextColor), -30, -10); objGraphics.ResetTransform(); //重置图像 Pen penDashed = new Pen(new SolidBrush(AxisColor)); for (int i = MinY; i <= MaxY; i++) { Scale = iHeight * (i - MinY) / (MaxY - MinY); if (i == MaxY) { objGraphics.DrawLine(penDashed, fltX1 + 5 * 1.5f, fltY1 - Scale, fltX2 - 5 * 1.5f, fltY1 - Scale); objGraphics.TranslateTransform(fltX1, fltY1 - Scale - 10); objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); objGraphics.DrawString(i.ToString(), new Font("SimSun", FontSize), new SolidBrush(SliceTextColor), -40, -10); objGraphics.ResetTransform(); } else { if (Scale - (iHeight * (iSliceCount - MinY) / (MaxY - MinY)) > 20) { objGraphics.DrawLine(penDashed, fltX1 + 5 * 1.5f, fltY1 - Scale, fltX2 - 5 * 1.5f, fltY1 - Scale); objGraphics.TranslateTransform(fltX1, fltY1 - Scale); objGraphics.RotateTransform(YRotateAngle, MatrixOrder.Prepend); objGraphics.DrawString(i.ToString(), new Font("SimSun", FontSize), new SolidBrush(SliceTextColor), -40, -10); objGraphics.ResetTransform(); iSliceCount = i; } } } } catch { } }