首页 > 编程语言 >关于Chart控件 C# 自定义

关于Chart控件 C# 自定义

时间:2023-12-20 19:22:20浏览次数:37  
标签:控件 自定义 C# series System using null dataViewer public

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.DataVisualization.Charting;

namespace PieChartLibrary
{
public class ViewProp
{
public Color[] SliceColors = null; // 饼图分片颜色
}

public class DataViewer
{
#region Data

public Dictionary<string, int> DataPoints = null; // 数据点列表
public ViewProp ViewProperty = null; // 绘图属性

#endregion
}

public class DrawPie
{
public List<DataViewer> DataList = null;

public void DrawPies(Chart chart)
{
if (DataList == null)
return;

// 创建和配置图例
Legend legend = new Legend();
legend.Docking = Docking.Bottom;
legend.Alignment = StringAlignment.Center;

foreach (DataViewer dataViewer in DataList)
{
// 创建新的数据系列
Series series = new Series();
series.ChartType = SeriesChartType.Pie;

// 设置饼图分片颜色并添加数据点
if (dataViewer.ViewProperty != null && dataViewer.ViewProperty.SliceColors != null)
{
List<Color> sliceColors = new List<Color>(dataViewer.ViewProperty.SliceColors);
int colorIndex = 0;

foreach (KeyValuePair<string, int> dataPoint in dataViewer.DataPoints)
{
// 创建数据点
DataPoint point = new DataPoint();
point.AxisLabel = dataPoint.Key; // 使用键作为标签
point.SetValueY(dataPoint.Value); // 使用值作为 Y 值

// 设置数据点颜色
if (colorIndex < sliceColors.Count)
{
point.Color = sliceColors[colorIndex]; // 设置数据点的颜色
colorIndex++;
}
// 设置饼图标签样式和线条颜色
series["PieLabelStyle"] = "Outside";
series["PieLineColor"] = "Black";
// 设置数据系列的标签格式为标签文本和百分比
series.Label = "#PERCENT{P0}";
series.Points.Add(point); // 添加数据点
}
}
series.Palette = ChartColorPalette.None;
series.IsVisibleInLegend = true; // 将数据系列显示在图例中

chart.Series.Add(series);// 添加数据系列

}

// 将图例添加到 Chart 控件上
chart.Legends.Add(legend);

}
}

 

----------------------------------------------------------------------------------------------------------------------------------------------------------

 

标签:控件,自定义,C#,series,System,using,null,dataViewer,public
From: https://www.cnblogs.com/wuchengyang/p/17917304.html

相关文章

  • 关于C#定时任务 job
    ////创建调度单元//Task<IScheduler>tsk=StdSchedulerFactory.GetDefaultScheduler();//ISchedulerscheduler=tsk.Result;////2.创建一个具体的作业即job(具体的job需要单独在一个文件中执行)//IJobDetailjob=JobBuil......
  • D. Three Activities
    原题链接穷举,属于模拟题,不要害怕注意,判断三天互不相同时要判断三次:a!=b,b!=c,c!=a代码#include<bits/stdc++.h>#definelllonglongusingnamespacestd;structunit{llv;lld;};lla[100005]={0};llb[100005]={0};llc[100005]={0};intmain(){i......
  • pip安装路径由.local调整为/usr/local
    如果没有设置PYTHONUSERBASE,默认会安装在~/.local下如果不希望安装在.local目录下,可以通过配置环境变量PYTHONUSERBASE指定对应的路径,比如/usr/local当然也可以直接修改site.py的_getuserbase方法,通过设置USER_SITE和USER_BASE来指定即调整USERSITE有2种方式:1.设置环境变量P......
  • Maix II Dock gpio子系统点亮LED学习
    一、Linux的gpio子系统1、Linux内核提供pinctrl子系统,目的为了统一各soc厂商的pin引脚管理;2、pinctrl子系统提供的功能①、管理系统中所有可控制的pin引脚:在系统初始化时候,枚举所有可控制的pin,并标识这些pin;②、管理这些pin的复用功能:配置若干引脚组......
  • 导入一个没有合并项 的excel表格
    导入excel///<summary>///导入设计地层单元数据-量纲设置///</summary>///<paramname="planId">方案ID</param>///<paramname="lists">录入基本信息</param>///<paramname="errorM......
  • An Introduction to Bioinformatics Algorithms, Neil C. Jones and Pavel Pevzner, t
    AnIntroductiontoBioinformaticsAlgorithms,NeilC.JonesandPavelPevzner,theMITPress,2004. Thisintroductorytextoffersaclearexpositionofthealgorithmicprinciplesdrivingadvancesinbioinformatics.Accessibletostudentsinbothbiology......
  • 关于C#文件的上传和下载,文件流相关
    文件的上传和下载控制器:///<summary>///上传web文件///</summary>///<paramname="files"></param>///<paramname="wellName">井名</param>///<paramname="userName&quo......
  • EasyCVR平台如何通过api接口设置实时流的sei数据实现画框等操作?
    为了便于用户自由调用、集成与二次开发,EasyCVR平台也提供了丰富的API接口供大家使用。今天我们来分享一下如何通过API接口设置实时流的SEI数据,实现在视频播放器中展示文本内容、画框等操作?1)后端接口调用如下:接口URL:POSThttp://127.0.0.1:18000/api/v1/sei/set2)接口参数如下:3)调用成......
  • Vite4+Typescript+Vue3+Pinia 从零搭建(7) - request封装
    项目代码同步至码云weiz-vue3-template基于axios封装请求,支持多域名请求地址安装npmiaxios封装utils目录下新建request文件夹,并新建index.ts、request.ts和status.ts文件。1.status.ts文件主要是封装状态码exportconstErrMessage=(status:number|s......
  • 如何解决MySQL Workbench中的错误Error Code: 1175
    错误描述:在MySQLWorkbench8.0中练习SQL语句时,执行一条update语句,总是提示如下错误:ErrorCode:1175.YouareusingsafeupdatemodeandyoutriedtoupdateatablewithoutaWHEREthatusesaKEYcolumnTodisablesafemode,toggletheoptioninPreferences->SQ......