图动态创建。在.NET,C#

编程入门 行业动态 更新时间:2024-10-11 03:24:05
本文介绍了图动态创建。在.NET,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有人有一些经验与图表的工作,在中?特别我想通过code来创建它们!

Does anybody have some experience working with charts, in ? Specially i want to create them by code!

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; using System.Diagnostics; namespace WindowsFormsApplication6 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Random rnd = new Random(); Chart mych = new Chart(); mych.Series.Add("duck"); mych.Series["duck"].SetDefault(true); mych.Series["duck"].Enabled = true; mych.Visible = true; for (int q = 0; q < 10; q++) { int first = rnd.Next(0,10); int second = rnd.Next(0,10); mych.Series["duck"].Points.AddXY(first, second); Debug.WriteLine(first + " " + second); } mych.Show(); Controls.Add(mych); mych.Show(); } } }

我想要使用的.Net(.NET 4时,Visual Studio 2010)图...但随机生成的数据集,并没有出现。只有出现一个空白,图表,我认为。我GOOGLE了它,却只有例子和教程像这和,是与它的工作手册拖的方法。我不知道为什么没有出现数据。请帮忙。 随机的事情显然作品;

i'm trying to use .Net ( 4, Visual Studio 2010) chart... but the random generated data set, doesn't appears. Only appears a blank, chart i think. I googled it, but there is only examples and tutorials like this , and, yes with manual "drag" method it works. I have no idea why not appearing the data. Please help. The random thing apparently works;

推荐答案

是的。

// FakeChart.cs // ------------------------------------------------------------------ // // A Winforms app that produces a contrived chart using // DataVisualization (MSChart). Requires 4.0. // // Author: Dino // // ------------------------------------------------------------------ // // compile: \net4.0\csc.exe /t:winexe /debug+ /R:\net4.0\System.Windows.Forms.DataVisualization.dll FakeChart.cs // using System; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; namespace Dino.Tools.WebMonitor { public class FakeChartForm1 : Form { private System.ComponentModel.IContainer components = null; System.Windows.Forms.DataVisualization.Charting.Chart chart1; public FakeChartForm1 () { InitializeComponent(); } private double f(int i) { var f1 = 59894 - (8128 * i) + (262 * i * i) - (1.6 * i * i * i); return f1; } private void Form1_Load(object sender, EventArgs e) { chart1.Series.Clear(); var series1 = new System.Windows.Forms.DataVisualization.Charting.Series { Name = "Series1", Color = System.Drawing.Color.Green, IsVisibleInLegend = false, IsXValueIndexed = true, ChartType = SeriesChartType.Line }; this.chart1.Series.Add(series1); for (int i=0; i < 100; i++) { series1.Points.AddXY(i, f(i)); } chart1.Invalidate(); } protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { thisponents = new System.ComponentModel.Container(); System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); this.SuspendLayout(); // // chart1 // chartArea1.Name = "ChartArea1"; this.chart1.ChartAreas.Add(chartArea1); this.chart1.Dock = System.Windows.Forms.DockStyle.Fill; legend1.Name = "Legend1"; this.chart1.Legends.Add(legend1); this.chart1.Location = new System.Drawing.Point(0, 50); this.chart1.Name = "chart1"; // this.chart1.Size = new System.Drawing.Size(284, 212); this.chart1.TabIndex = 0; this.chart1.Text = "chart1"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.chart1); this.Name = "Form1"; this.Text = "FakeChart"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); this.ResumeLayout(false); } /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FakeChartForm1()); } } }

用户界面:

更多推荐

图动态创建。在.NET,C#

本文发布于:2023-11-12 10:02:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!