📄 testcommonchartform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
using System.Drawing.Imaging;
using CommonComponent.CommonChart;
namespace TestCommonChart
{
/// <summary>
/// Summary description for GraphForm.
/// </summary>
public class TestCommonChartForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnChart;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.ComboBox cbType;
private System.Windows.Forms.Label label1;
//string strC ="user id=wpdm;password=wpdm;initial catalog=wpdm;data source=gfg2_nt_pdc;Connect Timeout=30";
//SqlConnection myConnection ;
//SqlDataAdapter myAdapter ;//
//SqlCommandBuilder myBuilder;//
//DataSet mySet;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public TestCommonChartForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnChart = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.cbType = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnChart
//
this.btnChart.Location = new System.Drawing.Point(352, 16);
this.btnChart.Name = "btnChart";
this.btnChart.Size = new System.Drawing.Size(88, 23);
this.btnChart.TabIndex = 0;
this.btnChart.Text = "生成图表(&G)";
this.btnChart.Click += new System.EventHandler(this.btnChart_Click);
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(16, 64);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(448, 336);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// cbType
//
this.cbType.Items.AddRange(new object[] {
"StackChartData",
"BarChartData",
"AreaData",
"MultiDataArea",
"PieChartData",
"MultiPieData",
"ChartData",
"MultiLineData",
"MultiIslandData\t"});
this.cbType.Location = new System.Drawing.Point(160, 16);
this.cbType.Name = "cbType";
this.cbType.Size = new System.Drawing.Size(168, 20);
this.cbType.TabIndex = 2;
//
// label1
//
this.label1.Font = new System.Drawing.Font("OpenSymbol", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 16);
this.label1.TabIndex = 3;
this.label1.Text = "清选择图表数据文件";
//
// TestCommonChartForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(480, 421);
this.Controls.Add(this.label1);
this.Controls.Add(this.cbType);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.btnChart);
this.Name = "TestCommonChartForm";
this.Text = "Common chart demo";
this.Load += new System.EventHandler(this.TestCommonChartForm_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
// [STAThread]
// static void Main()
// {
// Application.Run(new TestCommonChart());
// }
#region ["绘制图表类型"]
enum ChartType
{
StackChartData,
BarChartData,
AreaData,
MultiDataArea,
PieChartData,
MultiPieData,
ChartData,
MultiLineData,
MultiIslandData
};
#endregion
#region ["画图表"]
private void DrawChart(ChartType nType)
{
// Load XML data file.
string strFile = "ChartDemo.jpg";
XmlDocument obXmlDoc = null;
LineGraph2D obGraph = null;
Stream jpgFile = null;
string[] xmlDoc = {"StackChartData.xml","BarChartData.xml","AreaData.xml",
"MultiDataArea.xml", "PieChartData.xml","MultiPieData.xml","ChartData.xml",
"MultiLineData.xml","MultiIslandData.xml"};
try
{
jpgFile = new FileStream(strFile, FileMode.Create, FileAccess.ReadWrite);
obXmlDoc = new XmlDocument();
obXmlDoc.Load(xmlDoc[(int)nType]);
obGraph = new LineGraph2D();
//obGraph = new BarGraph3D();
//obGraph.BlocksBuffer = 5;
//obGraph.GraphAlignment = Alignment.Vertical;
obGraph.BackgroundColor = Color.Azure;
obGraph.UseGradientColors = true;
obGraph.Background = BackgroundType.LinearGradient;
//obGraph.Backgroud = BackgroundType.Image;
//obGraph.Backgroud = BackgroundType.Image;
obGraph.HatchColor = Color.AliceBlue;
obGraph.BackgroundHatchType = HatchType.HorizontalBrick;
//obGraph.BackgroundImage = "netdev.gif";
obGraph.CircularGradientType = CGradientType.InsideOut;
obGraph.LinearGradientType = LGradientType.ULeftToLRight;
obGraph.YTickSpacing = 100;
obGraph.IslandSpacing = 40.0F;
obGraph.SetTitle("Workers In U.S Labor Force");
//obGraph.BottomSpacing = 30.0F;
//obGraph.RightSpacing = 40.0F;
//obGraph.BoundingSquareSize = 150;
//obGraph.RadialTickerBuffer = 12.0F;
//set Graph feature
obGraph.SetTicker(false,false,true,true);
// obGraph.DrawXTickerText = false;
// obGraph.DrawYTickerText = false;
// obGraph.HasGridLines = true;
// obGraph.HasLegends = true;
// obGraph.HasTickers = true;
//set legend property
obGraph.SetLegendProperty(LegendAlignmentType.Vertical,PositionType.Right,LegendLocationType.InsideChart);
// obGraph.LegendAlignment = LegendAlignmentType.Vertical;
// obGraph.LegendPosition = PositionType.Right;
// obGraph.LegendLocation = LegendLocationType.InsideChart;
//set chart size
obGraph.SetChartSize(500,400);
// obGraph.Width = 500;
// obGraph.Height = 400;
//set xy axes value
obGraph.SetXYAxesRange(0,100,0,1000);
// obGraph.MinXValue = 0;
// obGraph.MaxXValue = 100;
// obGraph.MinYValue = 0;
// obGraph.MaxYValue = 1000;
//set side space
obGraph.SetSideSpace(60,60,30,30);
// obGraph.TopSpacing = 60;
// obGraph.BottomSpacing = 60;
// obGraph.LeftSpacing = 30;
// obGraph.RightSpacing = 60;
obGraph.SetGraphData (obXmlDoc);
obGraph.UseRandomColors = true;
IGraph obGraph1 = obGraph;
obGraph1.DrawGraph(ref jpgFile);
System.Drawing.Image myImage = Image.FromStream(jpgFile);
pictureBox1.Image=myImage;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (null != jpgFile)
{
jpgFile.Close();
}
}
}
#endregion
private void btnChart_Click(object sender, System.EventArgs e)
{
DrawChart((ChartType)cbType.SelectedIndex);
// DataSet mySet = new DataSet();
// SqlDataAdapter myAdapter = new SqlDataAdapter();
// myAdapter.SelectCommand.CommandText = "":
// myAdapter.SelectCommand.Connection.ConnectionString ="";
// myAdapter.Fill(mySet);
//
// mySet.Tables.Add("aa");
// label2.Text = mySet.Tables[0].Rows.Count.ToString();
// myConnection = new SqlConnection(strC);
// myAdapter = new SqlDataAdapter("Select Name,Address from tempTable1",myConnection);
// myBuilder = new SqlCommandBuilder(myAdapter);
// myConnection.Open();
// mySet = new DataSet();
// myAdapter.Fill(mySet);
// dataGrid1.DataSource = mySet.Tables[0];
// string filename = "C:\\test1.txt";
// FileStream fs = null;
// if(File.Exists(filename))
// {
// fs = new FileStream(filename,FileMode.Open,FileAccess.ReadWrite);
// }
// else
// {
// fs = new FileStream(filename,FileMode.Create,FileAccess.ReadWrite);
// }
//
// StreamWriter sw = new StreamWriter(fs,System.Text.Encoding.Default);
// sw.WriteLine("Test2");
// sw.WriteLine("测试");
// sw.WriteLine("Test2");
// sw.WriteLine(richTextBox1.Text);
// sw.Flush();
// sw.Close();
// fs.Close();
}
private void TestCommonChartForm_Load(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -