C# 使用使用GDI绘制雷达图的实例绘制雷达图的实例
主要介绍了C# 使用GDI绘制雷达图,本文通过一段实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,
需要的朋友可以参考下
最近项目要用C#实现画一个雷达图,搜了搜网上竟然找不到C#画雷达图的解决方案,那么自己实现一个吧
实现效果如下图:
代码如下:
public static class RadarDemo
{
static float mW = 1200;
static float mH = 1200;
static Dictionary<string, float> mData = new Dictionary<string, float>
{
//{ "速度",77},
{ "力量", 72},
{ "防守", 110},
{ "射门", 50},
{ "传球", 80},
{ "耐力", 60 }
};//维度数据
static float mCount = mData.Count; //边数
static float mCenter = mW * 0.5f; //中心点
static float mRadius = mCenter - 100; //半径(减去的值用于给绘制的文本留空间)
static double mAngle = (Math.PI * 2) / mCount; //角度
static Graphics graphics = null;
static int mPointRadius = 5; // 各个维度分值圆点的半径
static int textFontSize = 18; //顶点文字大小 px
const string textFontFamily = "Microsoft Yahei"; //顶点字体
static Color lineColor = Color.Green;
static Color fillColor = Color.FromArgb(128, 255, 0, 0);
static Color fontColor = Color.Black;
public static void Show()
{
Bitmap img = new Bitmap((int)mW, (int)mH);
graphics = Graphics.FromImage(img);
graphics.Clear(Color.White);
img.Save($"{AppDomain.CurrentDomain.BaseDirectory}radar/0.png", ImageFormat.Png);
DrawPolygon(graphics);
img.Save($"{AppDomain.CurrentDomain.BaseDirectory}radar/1.png", ImageFormat.Png);
DrawLines(graphics);
img.Save($"{AppDomain.CurrentDomain.BaseDirectory}radar/2.png", ImageFormat.Png);
DrawText(graphics);
评论0