欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#折線圖控件使用方法詳解

 更新時間:2022年02月17日 11:12:50   作者:bear_csdn  
這篇文章主要為大家詳細介紹了C#折線圖控件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C#編寫折線圖控件的具體代碼,供大家參考,具體內容如下

簡單解說

這是第一次寫博客,也是第一次發(fā)布自己寫代碼,有不足之處請多見諒。
源代碼參考了網絡搜索到的一些資源。
因為我需要的折線圖數據沒有小于0的,所以在計算時偷懶了。只支持大于0的數據。

上圖

如何插入一段漂亮的代碼片
因為自學編程,代碼注釋與命名比較亂,請見諒。
這是新建控件的代碼。需要給控件添加FoldLineDiagram_Resize 事件。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace vc_farm
{
? ? /// <summary>
? ? /// 折線圖控件
? ? /// 注意:
? ? /// 1、數據列最少不小于2列。
? ? /// 2、數據列與數據標題列長度必須保持一致
? ? /// 3、數據標題長度最大為100
? ? /// 4、折線數量不能大于10個
? ? /// </summary>
? ? public partial class FoldLineDiagram : UserControl
? ? {
? ? ? ??
? ? ? ? private Bitmap mImage; ? ? ? ? ? ? ?//畫的折線圖

? ? ? ? private FoldLineData mData; ? ? ? ? //記錄折線數據,在窗口大小改變時可重新計算

? ? ? ? private List<SelectionArea> mSelectionArea = new List<SelectionArea>(); ? ? //可選擇區(qū)域【此處無用,原用作記錄數據點,方便判斷光標是否選中某條數據折線】

? ? ? ? private SelectionArea mNowSelectionArea; ? ? ? ?//當前選中的區(qū)域【此處無用】

? ? ? ? public FoldLineDiagram()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? }

? ? ? ? #region 禁止基類屬性顯示
? ? ? ??

? ? ? ? [Browsable(false)]
? ? ? ? [EditorBrowsable(EditorBrowsableState.Never)]
? ? ? ? public override Image BackgroundImage
? ? ? ? {
? ? ? ? ? ? get { return base.BackgroundImage; }
? ? ? ? ? ? set { base.BackgroundImage = value; }
? ? ? ? }

? ? ? ? #endregion

? ? ? ? /// <summary>
? ? ? ? /// 獲取折線圖片(只有使用了ShowFoldLineDiagram方法后才能正確獲取)
? ? ? ? /// </summary>
? ? ? ? public Bitmap Image
? ? ? ? {
? ? ? ? ? ? get { return mImage; }
? ? ? ??
? ? ? ? }


? ? ? ? /// <summary>
? ? ? ? /// 顯示折線
? ? ? ? /// </summary>
? ? ? ? /// <param name="aData">折線數據對象</param>
? ? ? ? public void ShowFoldLineDiagram(FoldLineData aData)
? ? ? ? {
? ? ? ? ? ? this.mData = aData;
? ? ? ? ? ? mImage = CreateImageS(aData);

? ? ? ? ? ? this.BackgroundImage = new Bitmap(mImage); ? ? ?//背景為復制的圖片
? ? ? ? ? ? //this.BackgroundImageLayout = ImageLayout.Stretch; ? //拉伸顯示顯示
? ? ? ? }


? ? ? ? /// <summary>
? ? ? ? /// 保存 折線圖 圖片(只有使用了ShowFoldLineDiagram方法后才能正確保存)
? ? ? ? /// </summary>
? ? ? ? /// <param name="aSavePath">保存文件的路徑</param>
? ? ? ? /// <param name="aImageFormat">保存的格式</param>
? ? ? ? public void SaveImage(string aSavePath, System.Drawing.Imaging.ImageFormat aImageFormat)
? ? ? ? {
? ? ? ? ? ? new Bitmap(mImage).Save(aSavePath, aImageFormat);
? ? ? ? }

? ? ? ? private Bitmap CreateImageS(FoldLineData data)
? ? ? ? {

? ? ? ? ? ? #region 數據驗證
? ? ? ? ? ? if (data.DataTitleText.Count <= 1) return null; ? ? ? ? ? ? ? ? ? ? //限制列數不能小于2
? ? ? ? ? ? if (data.DataTitleText.Count >100) return null; ? ? ? ? ? ? ? ? ? ? //限制列數不能大于100
? ? ? ? ? ? if (data.listFoldLineDataStyle.Count > 10) return null; ? ? ? ? ? ? //限制折線數量不能大于10
? ? ? ? ? ? int temp = data.DataTitleText.Count; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//獲取數據標題長度
? ? ? ? ? ? for (int i = 0; i < data.listFoldLineDataStyle.Count; i++) ? ? ? ? ?//循環(huán)所有數據
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (data.listFoldLineDataStyle[i].Data.Count !=temp) ? ? ? ? ? ?//當前數據長度 ?與數據標題長度不一致
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? return null;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? #endregion

? ? ? ? ? ? #region 函數內部變量賦值

? ? ? ? ? ? this.mSelectionArea.Clear(); ? ? ? ? ? ? ? ? ? ? ? ? ? ?//記錄數據清空
? ? ? ? ? ??

? ? ? ? ? ? int height = this.Height, width = this.Width; ? ? ? ? ? ? ? ? ? ? ?//設置圖片大小
? ? ? ? ? ??
? ? ? ? ? ? //設置左右上下邊框距離圖片邊框間距
? ? ? ? ? ? int left = (int)(width * 0.1);
? ? ? ? ? ? int right = (int)(width * 0.1);
? ? ? ? ? ? int top = (int)(height * 0.1);
? ? ? ? ? ? int bottom;
? ? ? ? ? ? if (data.ShowLegend == true) bottom = (int)(height * 0.15); ? ? ? ? ?//顯示圖例時,下邊框為0.2
? ? ? ? ? ? else bottom = (int)(height * 0.1); ? ?
? ? ? ? ? ??

? ? ? ? ? ??
? ? ? ? ? ? #endregion

? ? ? ? ? ? Bitmap image = new Bitmap(width, height); ? ? ? ? ? //新建一張圖片
? ? ? ? ? ? Graphics g = Graphics.FromImage(image);
? ? ? ? ? ? g.SmoothingMode = SmoothingMode.AntiAlias; ?//使繪圖質量最高,即消除鋸齒
? ? ? ? ? ? g.InterpolationMode = InterpolationMode.HighQualityBicubic;
? ? ? ? ? ? g.CompositingQuality = CompositingQuality.HighQuality;

? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? #region 繪圖準備工作
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? g.Clear(Color.White); ? ? ? ? ? ? ? ? ? ? ? ? ? //清空圖片背景色

? ? ? ? ? ? ? ? Font font = data.DataTitleTextFont; ? ? ? ? //設置 X與Y軸 ?標題字體
? ? ? ? ? ? ? ? Font font1 = data.FoldLineTextFont; ? ? ? ?//設置 標題 ?字體
? ? ? ? ? ? ? ? //Font font2 = aLineDataFont; ? ? ? ?//設置 數據顯示 ?字體
? ? ? ? ? ? ? ? LinearGradientBrush brush = new LinearGradientBrush(
? ? ? ? ? ? ? ? new Rectangle(0, 0, image.Width, image.Height), data.BackgroundBorderColor, data.BackgroundBorderColor, 1.2f, true);
? ? ? ? ? ? ? ? g.FillRectangle(Brushes.AliceBlue, 0, 0, width, height);
? ? ? ? ? ? ? ? #endregion


? ? ? ? ? ? ? ? #region 畫折線圖標題
? ? ? ? ? ? ? ? Brush brush1 = new SolidBrush(data.FoldLineTextColor);
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? SizeF sizeF = g.MeasureString(data.FoldLineText, font1); ? ? ? ? ? ? //計算標題文字大小
? ? ? ? ? ? ? ? g.DrawString(data.FoldLineText, font1, brush1, (width - sizeF.Width) / 2, (top - sizeF.Height) / 2); ? ? ? ? ? ? //畫標題

? ? ? ? ? ? ? ? #endregion

? ? ? ? ? ? ? ? #region 繪制框線

? ? ? ? ? ? ? ? //畫圖片的邊框線
? ? ? ? ? ? ? ? g.DrawRectangle(new Pen(data.BackgroundBorderColor), 0, 0, image.Width - 1, image.Height - 1);

? ? ? ? ? ? ? ? Pen mypen = new Pen(brush, 1); ? ? ? ? ? ? ?//邊框線畫筆
? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? //繪制縱向線條
? ? ? ? ? ? ? ? int xLineSpacing = (width - left - right) / (data.DataTitleText.Count - 1); ? ? ? ? ? ?//計算X軸 線條間距
? ? ? ? ? ? ? ? int xPosition = left; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //X軸開始位置
? ? ? ? ? ? ? ? for (int i = 0; i < data.DataTitleText.Count; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? g.DrawLine(mypen, xPosition, top, xPosition, height - bottom); ? ? ? ? ? ? ? ? ? //畫X軸豎線

? ? ? ? ? ? ? ? ? ? sizeF = g.MeasureString(data.DataTitleText[i], font); ? ? ? ? ? ? //計算X軸文字大小
? ? ? ? ? ? ? ? ? ? g.DrawString(data.DataTitleText[i], font, new SolidBrush(data.DataTitleTextColor), xPosition - (sizeF.Width / 2), height - bottom ?+ 5); //設置文字內容及輸出位置

? ? ? ? ? ? ? ? ? ? xPosition += +xLineSpacing; ? ? ? ?//累加間距
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? //Pen mypen1 = new Pen(Color.Blue, 3);
? ? ? ? ? ? ? ? xPosition = left;
? ? ? ? ? ? ? ? g.DrawLine(mypen, xPosition, top, xPosition, height - bottom); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //畫X軸第1條線(粗線)

? ? ? ? ? ? ? ? //繪制橫向線條
? ? ? ? ? ? ? ? List<int> yName = ReckonYLine(data.listFoldLineDataStyle);
? ? ? ? ? ? ? ? int mLineCount = yName.Count; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//計算Y軸行數
? ? ? ? ? ? ? ? int yLineSpacing = (height - bottom - top) / (yName.Count - 1); ? ? ? ? ? //計算Y軸 線條間距
? ? ? ? ? ? ? ? int yPosition = height - bottom; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//Y軸開始點

? ? ? ? ? ? ? ? for (int i = 0; i < yName.Count; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? g.DrawLine(mypen, left, yPosition, width - right, yPosition);

? ? ? ? ? ? ? ? ? ? sizeF = g.MeasureString(yName[i].ToString(), font);
? ? ? ? ? ? ? ? ? ? g.DrawString(yName[i].ToString(), font, new SolidBrush(data.DataTitleTextColor), left - sizeF.Width - 5, yPosition - (sizeF.Height / 2)); //設置文字內容及輸出位置

? ? ? ? ? ? ? ? ? ? yPosition -= yLineSpacing;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? yPosition = height - bottom;
? ? ? ? ? ? ? ? g.DrawLine(mypen, left, yPosition, width - right, yPosition); ? ? ?//Y軸最下面一天線加粗
? ? ? ? ? ? ? ? #endregion

? ? ? ? ? ? ? ? #region 畫折線,及數據

? ? ? ? ? ? ? ? for (int i = 0; i < data.listFoldLineDataStyle.Count; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? //顯示折線效果
? ? ? ? ? ? ? ? ? ? Pen mypen2 = new Pen(data.listFoldLineDataStyle[i].FoldLineColor, 2); ? ? ? ? //折線畫筆
? ? ? ? ? ? ? ? ? ? List<int> pointData = data.listFoldLineDataStyle[i].Data; ? ? ? ? ? ? ? ? ? ? ? //取出折線數據

? ? ? ? ? ? ? ? ? ? xPosition = left;
? ? ? ? ? ? ? ? ? ? float yMultiple = (float)(height - top - bottom) / (float)yName.Max(); ? ? ? ? ? ?//計算Y軸比例因子

? ? ? ? ? ? ? ? ? ? List<Point> linePoint = new List<Point>(); ? ? ? ? ? ? ? ? ? ? ?//定義折線節(jié)點坐標
? ? ? ? ? ? ? ? ? ? for (int j = 0; j < pointData.Count; j++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Point point = new Point();
? ? ? ? ? ? ? ? ? ? ? ? point.X = xPosition;
? ? ? ? ? ? ? ? ? ? ? ? point.Y = top + (int)((yName.Max() - pointData[j]) * yMultiple);
? ? ? ? ? ? ? ? ? ? ? ? xPosition += xLineSpacing;
? ? ? ? ? ? ? ? ? ? ? ? linePoint.Add(point);
? ? ? ? ? ? ? ? ? ? ? ? g.FillEllipse(new SolidBrush(data.listFoldLineDataStyle[i].FoldLineColor), point.X - 5, point.Y - 5, 10, 10); ? ? ? ? ? //畫節(jié)點的圓點
? ? ? ? ? ? ? ? ? ? ? ? g.DrawString(pointData[j].ToString(), data.listFoldLineDataStyle[i].FoldLineDataFont, new SolidBrush(data.listFoldLineDataStyle[i].FoldLineDataColor), point.X, point.Y + 10); ? ? ? //繪制節(jié)點文字
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? g.DrawLines(mypen2, linePoint.ToArray()); //繪制折線?

? ? ? ? ? ? ? ? ? ? //記錄畫圖區(qū)域
? ? ? ? ? ? ? ? ? ? SelectionArea sa = new SelectionArea();
? ? ? ? ? ? ? ? ? ? sa.linePoint = linePoint;
? ? ? ? ? ? ? ? ? ? //sa.rect = new Rectangle();
? ? ? ? ? ? ? ? ? ? this.mSelectionArea.Add(sa);

? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? #endregion
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? #region 畫圖例

? ? ? ? ? ? ? ? if (data.ShowLegend ==true)
? ? ? ? ? ? ? ? {


? ? ? ? ? ? ? ? ? ? int length = 0; ? ? ? ? //繪制的長度
? ? ? ? ? ? ? ? ? ? for (int i = 0; i < data.listFoldLineDataStyle.Count; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? //顯示折線效果
? ? ? ? ? ? ? ? ? ? ? ? Pen mypen2 = new Pen(data.listFoldLineDataStyle[i].FoldLineColor, 2); ? ? ? ? //折線畫筆
? ? ? ? ? ? ? ? ? ? ? ? if (data.listFoldLineDataStyle[i].DataName == "折線")
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? data.listFoldLineDataStyle[i].DataName += i.ToString(); //如果是默認名稱,則給默認名稱加數字
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? sizeF = g.MeasureString(data.listFoldLineDataStyle[i].DataName, data.DataTitleTextFont); ? ? ? //計算字體長度
? ? ? ? ? ? ? ? ? ? ? ? //20:兩個圖例的間距,30:圖例中顏色表示區(qū)寬度 ,10:圖例顏色標識區(qū)與文本區(qū)間距
? ? ? ? ? ? ? ? ? ? ? ? length += 20 + 30 + 10 + (int)sizeF.Width;

? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? length += 20; ? //加上最后的間距

? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? int startX = (width - length) / 2;
? ? ? ? ? ? ? ? ? ? int startY = (int)(height * 0.92);
? ? ? ? ? ? ? ? ? ? for (int i = 0; i < data.listFoldLineDataStyle.Count; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? //顯示折線效果
? ? ? ? ? ? ? ? ? ? ? ? Pen mypen2 = new Pen(data.listFoldLineDataStyle[i].FoldLineColor, 2); ? ? ? ? //折線畫筆
? ? ? ? ? ? ? ? ? ? ? ? if (data.listFoldLineDataStyle[i].DataName == "折線")
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? data.listFoldLineDataStyle[i].DataName += i.ToString(); //如果是默認名稱,則給默認名稱加數字
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? sizeF = g.MeasureString(data.listFoldLineDataStyle[i].DataName, data.DataTitleTextFont); ? ? ? //計算字體長度

? ? ? ? ? ? ? ? ? ? ? ? g.FillRectangle(new SolidBrush(data.listFoldLineDataStyle[i].FoldLineColor), startX, startY, 30, 10); //繪制小矩形
? ? ? ? ? ? ? ? ? ? ? ? g.DrawString(data.listFoldLineDataStyle[i].DataName, data.DataTitleTextFont, new SolidBrush(data.listFoldLineDataStyle[i].FoldLineColor), startX ?+ 30 + 10, startY);
? ? ? ? ? ? ? ? ? ? ? ? startX += 30 + 10 + (int)sizeF.Width+20;


? ? ? ? ? ? ? ? ? ? ? ? //記錄畫圖區(qū)域的 圖例顯示區(qū)域
? ? ? ? ? ? ? ? ? ? ? ? Rectangle rect = new Rectangle(startX, startY, 30, 10);
? ? ? ? ? ? ? ? ? ? ? ? SelectionArea sa = this.mSelectionArea[i];
? ? ? ? ? ? ? ? ? ? ? ? sa.rect = rect;
? ? ? ? ? ? ? ? ? ? ? ? this.mSelectionArea[i] = sa;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? #endregion
? ? ? ? ? ? ? ? return new Bitmap(image);
? ? ? ? ? ? }
? ? ? ? ? ? finally
? ? ? ? ? ? {
? ? ? ? ? ? ? ? g.Dispose();
? ? ? ? ? ? ? ? image.Dispose();
? ? ? ? ? ? }

? ? ? ? }

? ? ? ? /// <summary>
? ? ? ? /// Y軸橫線 及 Y軸標題內如 計算?
? ? ? ? /// </summary>
? ? ? ? /// <param name="data"></param>
? ? ? ? /// <returns></returns>
? ? ? ? private List<int> ReckonYLine(List<FoldLineDataStyle> flData)
? ? ? ? {
? ? ? ? ? ? List<int> AllData = new List<int>(); ? ? ? ?//所有數據匯總在一起?
? ? ? ? ? ? foreach (FoldLineDataStyle item in flData)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? AllData.AddRange(item.Data);
? ? ? ? ? ? }

? ? ? ? ? ? //定義最大值與最小值
? ? ? ? ? ? int max = AllData.Max();
? ? ? ? ? ? int min = AllData.Min();
? ? ? ? ? ? List<int> yName = new List<int>();

? ? ? ? ? ? int csMax = 0; ? ? ? //測算上限
?? ??? ??? ?/*如果需要增加小于0數據判斷,則需要在此次增加一些判斷。
?? ??? ??? ?*就是取最小值,判斷是否為負數,是則取絕對值進行計算,不是則和現在計算方式一樣
?? ??? ??? ?*/
? ? ? ? ? ? if (max.ToString().Length > 1) ? ? ? ?//如果大于9
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //測算最大上限值
? ? ? ? ? ? ? ? string ling = "";
? ? ? ? ? ? ? ? for (int i = 0; i < max.ToString().Length - 1; i++) ? ? ? ? ? ? ? ? ? ?//為數字末尾補0
? ? ? ? ? ? ? ? ? ? ling += "0";

? ? ? ? ? ? ? ? string temp = max.ToString().Substring(0, 1); ? ? ? ? ? //取出最高位數字
? ? ? ? ? ? ? ? csMax = Int32.Parse((Int32.Parse(temp) + 1) + ling); ? //如果max=75162 則轉成 80000

? ? ? ? ? ? ? ? for (int i = 0; i <= (Int32.Parse(temp) + 1); i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? yName.Add((Int32.Parse(i + ling)));
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? csMax = max + 1;
? ? ? ? ? ? ? ? for (int i = 0; i <= csMax; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? yName.Add(i);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }

? ? ? ? ? ? return yName;
? ? ? ? }

? ? ? ? private void FoldLineDiagram_Resize(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (mData!=null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? mImage = CreateImageS(mData);
? ? ? ? ? ? ? ? this.BackgroundImage = new Bitmap(mImage); ? ? ?//背景為復制的圖片
? ? ? ? ? ? }
? ? ? ? }


? ? ? ? /// <summary>
? ? ? ? /// 選擇區(qū)域
? ? ? ? /// </summary>
? ? ? ? private struct SelectionArea
? ? ? ? {
? ? ? ? ? ? /// <summary>
? ? ? ? ? ? /// 選擇區(qū)域
? ? ? ? ? ? /// </summary>
? ? ? ? ? ? public Rectangle rect;

? ? ? ? ? ? /// <summary>
? ? ? ? ? ? /// 折線區(qū)域
? ? ? ? ? ? /// </summary>
? ? ? ? ? ? public List<Point> linePoint; ??
? ? ? ??
? ? ? ? }

? ?
? ? ? ? /// <summary>
? ? ? ? /// 判斷點是否在矩形范圍內
? ? ? ? /// </summary>
? ? ? ? /// <param name="rect"></param>
? ? ? ? /// <param name="pt"></param>
? ? ? ? /// <returns></returns>
? ? ? ? public static bool IsPointIn(RectangleF rect, PointF pt)
? ? ? ? {
? ? ? ? ? ? if (pt.X >= rect.X && pt.Y >= rect.Y && pt.X <= rect.X + rect.Width && pt.Y <= rect.Y + rect.Height)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? ? ? else return false;
? ? ? ? }

? ? }


? ? /// <summary>
? ? /// 折線背景設置
? ? /// </summary>
? ? public class FoldLineData
? ? {
? ? ? ? /// <summary>
? ? ? ? /// 全部折線 ? ?默認:空數據
? ? ? ? /// </summary>
? ? ? ? public List<FoldLineDataStyle> listFoldLineDataStyle;

? ? ? ? /// <summary>
? ? ? ? /// 折線圖的標題文本 ? ?默認:空文本
? ? ? ? /// </summary>
? ? ? ? public List<string> DataTitleText;

? ? ? ? /// <summary>
? ? ? ? /// 折線圖的標題文本 ? ?默認:空文本
? ? ? ? /// </summary>
? ? ? ? public string FoldLineText;

? ? ? ? /// <summary>
? ? ? ? /// 折線圖的標題文本 字體顏色 ? ?默認:黑色
? ? ? ? /// </summary>
? ? ? ? public Color FoldLineTextColor;

? ? ? ? /// <summary>
? ? ? ? /// 折線圖的標題文本 字體格式 ? ?默認:"宋體", 20
? ? ? ? /// </summary>
? ? ? ? public Font FoldLineTextFont;

? ? ? ? /// <summary>
? ? ? ? /// 數據列標題 字體顏色 ? ?默認:黑色
? ? ? ? /// </summary>
? ? ? ? public Color DataTitleTextColor;

? ? ? ? /// <summary>
? ? ? ? /// 數據列標題 字體格式 ? ?默認:"宋體", 9
? ? ? ? /// </summary>
? ? ? ? public Font DataTitleTextFont;

? ? ? ? /// <summary>
? ? ? ? /// 背景邊框線 顏色 ? ?默認:深灰色
? ? ? ? /// </summary>
? ? ? ? public Color BackgroundBorderColor;

? ? ? ? /// <summary>
? ? ? ? /// 顯示圖例 ? ?默認:true
? ? ? ? /// </summary>
? ? ? ? public bool ShowLegend;

? ? ? ? /// <summary>
? ? ? ? /// 構造函數
? ? ? ? /// </summary>
? ? ? ? /// <param name="flds">數據組。每組數據長度必須一致,且與數據列名稱長度一致</param>
? ? ? ? /// <param name="dataTitleText">數據列名稱</param>
? ? ? ? public FoldLineData(List<FoldLineDataStyle> flds, List<string> dataTitleText)
? ? ? ? {

? ? ? ? ? ? DataTitleText = dataTitleText;
? ? ? ? ? ? listFoldLineDataStyle = flds;
? ? ? ? ? ? FoldLineText = "";
? ? ? ? ? ? FoldLineTextColor = Color.Black;
? ? ? ? ? ? FoldLineTextFont = new System.Drawing.Font("宋體", 20, FontStyle.Regular);
? ? ? ? ? ? DataTitleTextColor = Color.Black;
? ? ? ? ? ? DataTitleTextFont = new System.Drawing.Font("Arial", 9, FontStyle.Regular);
? ? ? ? ? ? BackgroundBorderColor = Color.DarkGray;
? ? ? ? ? ? ShowLegend = true;
? ??
? ? ? ? }
? ??
? ? }


? ? /// <summary>
? ? /// 折線數據及樣式
? ? /// </summary>
? ? public class FoldLineDataStyle
? ? {

? ? ? ? /// <summary>
? ? ? ? /// 折線數據 ? ?默認:null
? ? ? ? /// </summary>
? ? ? ? public List<int> Data;

? ? ? ? /// <summary>
? ? ? ? /// 折線數據名稱 ? ?默認:折線
? ? ? ? /// </summary>
? ? ? ? public string DataName;

? ? ? ? /// <summary>
? ? ? ? /// 折線顏色 ? ?默認:紅色
? ? ? ? /// </summary>
? ? ? ? public Color FoldLineColor;

? ? ? ? /// <summary>
? ? ? ? /// 折線點上 顯示的數據顏色 ? ?默認:紅色
? ? ? ? /// </summary>
? ? ? ? public Color FoldLineDataColor;

? ? ? ? /// <summary>
? ? ? ? /// 折線點上 顯示的數據字體格式 ? ?默認:"宋體", 8
? ? ? ? /// </summary>
? ? ? ? public Font FoldLineDataFont;

? ? ? ? /// <summary>
? ? ? ? /// 構造函數
? ? ? ? /// </summary>
? ? ? ? /// <param name="data">數據。數據長度一定需要保持一致</param>
? ? ? ? public FoldLineDataStyle(List<int> data)
? ? ? ? {
? ? ? ? ? ? Data = data;
? ? ? ? ? ? FoldLineColor = Color.Red;
? ? ? ? ? ? FoldLineDataColor = Color.Red;
? ? ? ? ? ? FoldLineDataFont = new System.Drawing.Font("宋體", 9, FontStyle.Regular);
? ? ? ? ? ? DataName = "折線";
? ? ? ??
? ? ? ? }
? ??
? ? }
}

測試數據代碼

private void Form2_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? List<string> name = new List<string> { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月" };
? ? ? ? ? ? List<int> data = new List<int> { 1150, 250, 1550, 1600, 1800, 900, 2500, 1700 };
? ? ? ? ? ? List<int> data1 = new List<int> { 1250, 2250, 3550, 1600, 800, 900, 500, 2700 };
? ? ? ? ? ? List<int> data2 = new List<int> { 2150, 250, 1550, 1600, 1700, 900, 200, 1700 };
? ? ? ? ? ? FoldLineDataStyle fld = new FoldLineDataStyle(data);?? ?//默認格式
? ? ? ? ? ??
? ? ? ? ? ? FoldLineDataStyle fld1 = new FoldLineDataStyle(data1);
? ? ? ? ? ? fld1.DataName = "測試數據1";
? ? ? ? ? ? fld1.FoldLineColor = Color.Green;
? ? ? ? ? ? fld1.FoldLineDataColor = Color.Green;

? ? ? ? ? ? FoldLineDataStyle fld2 = new FoldLineDataStyle(data2);
? ? ? ? ? ? //fld2.DataName = "測試數據1";
? ? ? ? ? ? fld2.FoldLineColor = Color.Blue;
? ? ? ? ? ? fld2.FoldLineDataColor = Color.Blue;

? ? ? ? ? ? FoldLineData foldLineData = new FoldLineData(new List<FoldLineDataStyle> { fld, fld1, fld2 }, name);
? ? ? ? ? ? foldLineData.ShowLegend = true;
? ? ? ? ? ? foldLineData.FoldLineText = "測試折線圖";
? ? ? ? ? ? this.foldLineDiagram1.ShowFoldLineDiagram(foldLineData);
? ? ? ? }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • C#中List<T>存放元素的工作機制

    C#中List<T>存放元素的工作機制

    這篇文章介紹了C#中List<T>存放元素的工作機制,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • c# 閉包的相關知識以及需要注意的地方

    c# 閉包的相關知識以及需要注意的地方

    這篇文章主要介紹了c# 閉包的相關知識以及需要注意的地方,文中講解非常細致,代碼幫助大家理解和學習,感興趣的朋友可以參考下
    2020-06-06
  • Unity實現引導頁效果

    Unity實現引導頁效果

    這篇文章主要為大家詳細介紹了Unity實現引導頁效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • winform模擬鼠標按鍵的具體實現

    winform模擬鼠標按鍵的具體實現

    這篇文章介紹了winform模擬鼠標按鍵的具體實現,有需要的朋友可以參考一下
    2013-10-10
  • C#實現字符串倒序遍歷的方法小結

    C#實現字符串倒序遍歷的方法小結

    這篇文章主要為大家詳細介紹了C#中實現字符串倒序遍歷的常見方法,文中的示例代碼講解詳細,具有一定的借鑒價值,有需要的小伙伴可以參考下
    2024-02-02
  • C# 延遲Task.Delay()和Thread.Sleep()的具體使用

    C# 延遲Task.Delay()和Thread.Sleep()的具體使用

    Thread.Sleep()是同步延遲,Task.Delay()是異步延遲,本文主要介紹了C# 延遲Task.Delay()和Thread.Sleep()的具體使用,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學習學習吧
    2024-01-01
  • C#操作XML方法詳解

    C#操作XML方法詳解

    對于XML讀寫操作,項目中經常要用到,之前木有好好總結過,例如LINQ TO XML也用過,這篇文章主要介紹了C#操作XML的方法
    2021-11-11
  • C#讀取文件所有行到數組的方法

    C#讀取文件所有行到數組的方法

    這篇文章主要介紹了C#讀取文件所有行到數組的方法,涉及C#針對文件及數組的相關操作技巧,需要的朋友可以參考下
    2015-07-07
  • Unity中的PostProcessScene實用案例深入解析

    Unity中的PostProcessScene實用案例深入解析

    這篇文章主要為大家介紹了Unity中的PostProcessScene實用案例深入解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-05-05
  • C#文件非占用讀取與幫助類FileHelper

    C#文件非占用讀取與幫助類FileHelper

    這篇文章介紹了C#文件非占用讀取與幫助類FileHelper,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04

最新評論