c#利用Chart 画图

c#利用Chart 画图

添加画图组件

编写代码

复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace huatu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 设置曲线的样式

            Series series = chart1.Series[0];

            // 画样条曲线(Spline)
            series.ChartType = SeriesChartType.Spline;
            //series.ChartType = SeriesChartType.Point;

            // 线宽2个像素
            series.BorderWidth = 2;

            // 线的颜色:红色
            series.Color = System.Drawing.Color.Red;

            // 图示上的文字
            series.LegendText = "演示曲线";

            // 准备数据
            float[] values = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };

            // 在chart中显示数据
            int x = 0;
            foreach (float v in values)
            {
                series.Points.AddXY(x, v);
                x++;
            }

            // 设置显示范围
            ChartArea chartArea = chart1.ChartAreas[0];
            chartArea.AxisX.Minimum = 0;
            chartArea.AxisX.Maximum = 10;
            chartArea.AxisY.Minimum = 0d;
            chartArea.AxisY.Maximum = 1.1d;
        }
    }
}
相关推荐
Highcharts.js3 小时前
成分占比饼图代码|常用可视化图表开发示例
java·开发语言·仪表盘·highcharts·实战代码·响应式图表
蓝博AI4 小时前
2027基于yolov8飞机蒙皮缺陷检测,支持图像,视频和摄像实时检测,python源码
开发语言·python·yolo
郝学胜-神的一滴6 小时前
游戏设计、原型与开发 26:四种循环
开发语言·数据结构·游戏·游戏引擎·游戏策划
泡海椒7 小时前
Java PDF 报表开发:一页简历的两种版式风格对比与折行避坑
java·开发语言·pdf
2601_962885727 小时前
如何用 Python 计算终极振荡器(Ultimate Oscillator, UOS)?
开发语言·python
benchmark_cc9 小时前
一次获取多只股票实时行情:QuantDash `quotes.get(symbols=[...])` 批量快照
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
geovindu9 小时前
python: PCA
开发语言·后端·python·算法
__万波__9 小时前
嵌入式存储技术--1.Flash物理存储
java·开发语言
Chen_harmony10 小时前
十六、ALV树
开发语言·c++
qq_2744751510 小时前
第 28 篇:Promise 全解析:状态、then/catch/finally、静态方法 all/race/allSettled/any
开发语言·javascript