概述
使用微软Chart控件,绘制两条折线图。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace 图表练习
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// 设置曲线的样式
Series series1 = new Series();
series1 = chart1.Series[0];
series1.ChartType = SeriesChartType.Spline;
series1.BorderWidth = 2;
series1.Color = Color.Red;
series1.LegendText = "第一条线";
Series series2 = new Series();
series2 = chart1.Series[1];
series2.ChartType = SeriesChartType.Line;
series2.BorderWidth = 2;
series2.Color = Color.Green;
series2.LegendText = "第二条线";
// 准备数据
int[] myValues1 = { 3, 4, 5, 6, 7, 8, 8, 4, 3, 2, 9, 6, 8, 4, 2, 9, 1, 2, 5, 6, 8, 9, 1, 2, 3, 4, 4, 8 };
int[] myValues2 = { 13, 13, 14, 15, 16, 17, 18, 19, 10, 14, 17, 19, 14, 13, 19, 11, 12, 15, 16, 17, 19, 11 };
// 在chart中显示数据
int xValue1 = 0;
int xValue2 = 0;
foreach (int yValue1 in myValues1)
{
series1.Points.AddXY(xValue1, yValue1);
xValue1++;
}
foreach (int yValue2 in myValues2)
{
series2.Points.AddXY(xValue2, yValue2);
xValue2++;
}
// 设置显示范围
ChartArea myChartArea = chart1.ChartAreas[0];
myChartArea.AxisX.Minimum = 0;
myChartArea.AxisX.Maximum = 30;
myChartArea.AxisY.Minimum = 0;
myChartArea.AxisY.Maximum = 20;
}
}
}
最后
以上就是明理小甜瓜为你收集整理的【C#语言】绘制两条折线图的全部内容,希望文章能够帮你解决【C#语言】绘制两条折线图所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复