📄 piegraph3d.cs
字号:
// Disclaimer and Copyright Information
// PieGraph3D.cs :
//
// All rights reserved.
//
// Written by Pardesi Services, LLC
// Version 1.01
//
// Distribute freely, except: don't remove our name from the source or
// documentation (don't take credit for my work), mark your changes (don't
// get me blamed for your possible bugs), don't alter or remove this
// notice.
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc. to
// softomatix@CommonComponent.com
///////////////////////////////////////////////////////////////////////////////
//
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
namespace CommonComponent.CommonChart
{
/// <summary>
///
/// </summary>
public class PieGraph3D : CommonChart.PieGraph
{
protected float m_fShadowDepthFraction;
public PieGraph3D()
{
//
// TODO: Add constructor logic here
//
this.m_GraphType = Type.PieGraph3D;
m_fShadowDepthFraction = 0.03F;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
override protected bool DrawData()
{
//TODO: For now we will process only first array of data list. Later
// on implementation needs to take into account that there may
// be more than one list.
float fRadius = 0.0F;
PointF ptCenter;
SolidBrush tickerBrush = null;
Pen piePen = null;
Pen obTickerPen = null;
RectangleF boundingRect;
RectangleF shadowRect;
float fDepth = 0.0F;
try
{
// Calculate bounding sqaure size and other measurements.
this.CalculateDrawingMeasurements();
fDepth = this.BoundingSquareSize * this.m_fShadowDepthFraction;
ArrayList dataList = (ArrayList)this.m_obIslandList[0];
if (null == dataList || dataList.Count == 0)
{
throw new Exception("There is no data list present in the array.");
}
int nCount = dataList.Count;
if (this.UseRandomColors)
{
ColorUtil.GenerateRandomColors(nCount, out m_arrColors);
}
else
{
ColorUtil.GenerateColorValues(this.Colors, out m_arrColors);
}
// Create Black pen for drawing pie outlines.
piePen = new Pen(new SolidBrush(Color.Gray));
piePen.Width = 0.1F;
// Create brush for drawing tickers.
if (this.HasTickers)
{
tickerBrush = new SolidBrush(this.m_TickColor);
obTickerPen = new Pen(tickerBrush);
}
boundingRect = new RectangleF();
boundingRect.Width = BoundingSquareSize;
boundingRect.Height = BoundingSquareSize;
boundingRect.Y = this.m_ChartRectangle.Y + (LeftOverHeight/2.0F);
shadowRect = new RectangleF();
shadowRect.Width = BoundingSquareSize;
shadowRect.Height = BoundingSquareSize;
shadowRect.Y = boundingRect.Y + fDepth;
ptCenter = new PointF();
ptCenter.X = boundingRect.X + boundingRect.Width/2.0F ;
ptCenter.Y = boundingRect.Y + (int)((boundingRect.Height + fDepth)/2.0F);
// Calculate radius.
fRadius = (boundingRect.Width + fDepth)/2.0F;
float fStartX = this.m_ChartRectangle.X + LeftOverWidth/2.0F;
float currentDegree = 0.0F;
for (int nIdx = 0; nIdx < this.m_obDataIslandNodes.Count; nIdx++)
{
shadowRect.X = fStartX + fDepth;
if (nIdx > 0)
{
shadowRect.X += nIdx * (IslandSpacing + BoundingSquareSize);
}
ptCenter.X = shadowRect.X + shadowRect.Width/2.0F;
currentDegree = 0.0F;
ArrayList obIslandDataList = (ArrayList)this.m_obIslandList[nIdx];
for (int idx = 0; idx < nCount; idx++)
{
GraphDataObject obData = (GraphDataObject)obIslandDataList[idx];
if (null != obData)
{
float val = (float)((obData.Y / ((float)100.0)) * 360.0);
if (val > 0.0)
{
Color shadowColor = ColorUtil.GetDarkColor((Color)(this.m_arrColors[idx]), -40);
this.m_obGraphics.FillPie(new SolidBrush(shadowColor),
shadowRect.X, shadowRect.Y, shadowRect.Width, shadowRect.Height,
currentDegree, val);
// increment the currentDegree
currentDegree += (float)(obData.Y / 100 * 360);
}
}
}
boundingRect.X = fStartX;
if (nIdx > 0)
{
boundingRect.X += nIdx * (IslandSpacing + BoundingSquareSize);
}
ptCenter.X = boundingRect.X + boundingRect.Width/2.0F;
currentDegree = 0.0F;
for (int idx = 0; idx < nCount; idx++)
{
GraphDataObject obData = (GraphDataObject)obIslandDataList[idx];
if (null != obData)
{
float val = (float)((obData.Y / ((float)100.0)) * 360.0);
if (val > 0.0)
{
Color opaqueColor = ColorUtil.GetOpaqueColor((Color)(this.m_arrColors[idx]));
this.m_obGraphics.FillPie(new SolidBrush(opaqueColor),
boundingRect.X, boundingRect.Y, boundingRect.Width, boundingRect.Height,
currentDegree, val);
this.m_obGraphics.DrawPie(piePen, boundingRect, currentDegree, val);
if (this.HasTickers)
{
this.DrawChartTicker(this.m_obGraphics,
tickerBrush,
obTickerPen,
new Point((int)ptCenter.X, (int)ptCenter.Y),
fRadius,
m_fRadialTickerBuffer,
(currentDegree + val/2.0F),
obData.Y.ToString(),
this.m_LegendsList[idx]);
}
// increment the currentDegree
currentDegree += (float)(obData.Y / 100 * 360);
}
}
}
// Draw Island legend.
if (this.DrawIslandLegend)
{
PointF txtPt = new PointF(boundingRect.X, boundingRect.Y);
this.DrawIslandLegendText(m_IslandLegendsList[nIdx], m_obGraphics, IslandLegendFont, txtPt, BoundingSquareSize, this.m_TickColor);
}
}
}
finally
{
if (null != piePen)
{
piePen.Dispose();
}
if (null != obTickerPen)
{
obTickerPen.Dispose();
}
if (null != tickerBrush)
{
tickerBrush.Dispose();
}
}
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -