|
|
|
|
|
|
|
|
There are currently:
8 anonymous users online.
0 of 3,596 registered users online.
There have been 292475 Page Hits by
210466 users
|
|
|
|
|
Base Example
The following examples on this page generate the following chart
For lots more example code, you can click on any chart in the galleries to see
the code that generates them.
C# Code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using SasqChart;
namespace Chart
{
/// <summary>
/// Summary description for Example.
/// </summary>
public class Example : System.Windows.Forms.Form
{
private SasqChart.FormChartControl chart1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Example()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
PopulateChart();
}
private void PopulateChart()
{
Random myRandom = new Random();
// Create a DataSet
DataSet myDataSet = new DataSet();
// Get the first DataTable
DataTable myDataTable = myDataSet.Tables.Add("Sales");
// Create Columns
myDataTable.Columns.Add("label", typeof(string));
myDataTable.Columns.Add("value1", typeof(int) );
myDataTable.Columns.Add("value2", typeof(int) );
myDataTable.Columns.Add("value3", typeof(int) );
// Fill in data table
for(int i=0; i<20; i++)
{
DataRow myDataRow = myDataTable.NewRow();
myDataRow["label"] = i.ToString();
myDataRow["value1"] = myRandom.Next(100) - 50;
myDataRow["value2"] = myRandom.Next(100);
myDataRow["value3"] = myRandom.Next(100) + 50;
myDataTable.Rows.Add(myDataRow);
}
// Chart 1
chart1.ChartStyle.FillColor = Color.Blue;
chart1.ChartStyle.FillColorAlternate = Color.White;
chart1.ChartStyle.Type = SasqChart.Style.FillType.GradientForwardDiagonal;
chart1.Series[0].Type = ChartType.SmoothLine;
chart1.Series[1].Type = ChartType.SmoothLine;
chart1.Series[2].Type = ChartType.SmoothLine;
chart1.LabelColumnName = "label";
chart1.Series[0].DataProviderColumnNames.Value = "value1";
chart1.Series[1].DataProviderColumnNames.Value = "value2";
chart1.Series[2].DataProviderColumnNames.Value = "value3";
chart1.DataSource = myDataSet;
chart1.DataBind();
}
/// <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.chart1 = new SasqChart.FormChartControl();
this.SuspendLayout();
//
// chart1
//
this.chart1.Dock = System.Windows.Forms.DockStyle.Fill;
this.chart1.Header.Text = "Example Chart";
this.chart1.ChartStyle.FontColor = System.Drawing.Color.Black;
this.chart1.ChartStyle.Font = new System.Drawing.Font("Arial", 8F);
this.chart1.Location = new System.Drawing.Point(0, 0);
this.chart1.Name = "Example Chart";
this.chart1.Padding = 10;
this.chart1.Size = new System.Drawing.Size(500, 500);
this.chart1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(500, 500);
this.Controls.Add(this.chart1);
this.Name = "Example Chart";
this.Resize += new System.EventHandler(this.Form_Resize);
this.ResumeLayout(false);
}
#endregion
private void Form_Resize(object sender, System.EventArgs e)
{
Invalidate();
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Example());
}
}
}
|