private void InitializeComponent()
{
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();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
this.toolStripContainer1.ContentPanel.SuspendLayout();
this.toolStripContainer1.SuspendLayout();
this.SuspendLayout();
//
// chart1
//
chartArea1.Area3DStyle.Enable3D = true;
chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisX.IntervalOffset = 1;
chartArea1.AxisX.IsLabelAutoFit = false;
chartArea1.AxisX.LabelStyle.Angle = 90;
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Dock = System.Windows.Forms.DockStyle.Fill;
legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Bottom;
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(0, 0);
this.chart1.Name = "chart1";
series1.ChartArea = "ChartArea1";
series1.IsValueShownAsLabel = true;
series1.Legend = "Legend1";
series1.LegendText = "PC";
series1.Name = "Series1";
series1.XValueMember = "SaleMonth";
series1.YValueMembers = "DepQty,DepID";
series1.YValuesPerPoint = 2;
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(534, 417);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";
//
// toolStripContainer1
//
//
// toolStripContainer1.ContentPanel
//
this.toolStripContainer1.ContentPanel.Controls.Add(this.chart1);
this.toolStripContainer1.ContentPanel.Size = new System.Drawing.Size(534, 417);
this.toolStripContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.toolStripContainer1.Location = new System.Drawing.Point(0, 0);
this.toolStripContainer1.Name = "toolStripContainer1";
this.toolStripContainer1.Size = new System.Drawing.Size(534, 417);
this.toolStripContainer1.TabIndex = 1;
this.toolStripContainer1.Text = "toolStripContainer1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(534, 417);
this.Controls.Add(this.toolStripContainer1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
this.toolStripContainer1.ContentPanel.ResumeLayout(false);
this.toolStripContainer1.ResumeLayout(false);
this.toolStripContainer1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
private System.Windows.Forms.ToolStripContainer toolStripContainer1;
}
}
using System;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace MSChartDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chart1.DataSource = new DataInfo().GetDataTable();
chart1.DataBind();
SetAnn();
}
private void SetAnn()
{
CalloutAnnotation caMax = new CalloutAnnotation();
caMax.Name = "caMax";
caMax.Text = "賣最好";
caMax.ToolTip = "金額 : #VAL{#,##0}";
caMax.CalloutStyle = CalloutStyle.Rectangle;
caMax.AnchorDataPoint = chart1.Series[0].Points.FindMaxByValue();
caMax.Width = double.NaN;
caMax.Height = double.NaN;
caMax.X = double.NaN;
caMax.Y = double.NaN;
caMax.AllowMoving = true;
if (chart1.Annotations.FindByName("caMax") != null)
{
chart1.Annotations.Remove(chart1.Annotations.FindByName("caMax"));
}
chart1.Annotations.Add(caMax);
//最大值的直條圖設為紅色
chart1.Series[0].Points.FindMaxByValue().Color = System.Drawing.Color.Red;
CalloutAnnotation caMin = new CalloutAnnotation();
caMin.Name = "caMin";
caMin.Text = "賣最差";
caMin.ToolTip = "金額 : #VAL{#,##0}";
caMin.CalloutStyle = CalloutStyle.RoundedRectangle;
caMin.AnchorDataPoint = chart1.Series[0].Points.FindMinByValue();
caMin.Width = double.NaN;
caMin.Height = double.NaN;
caMin.X = double.NaN;
caMin.Y = double.NaN;
caMin.AllowMoving = true;
if (chart1.Annotations.FindByName("caMin") != null)
{
chart1.Annotations.Remove(chart1.Annotations.FindByName("caMin"));
}
//最小值的直條圖設為黑色
chart1.Series[0].Points.FindMinByValue().Color = System.Drawing.Color.Black;
chart1.Annotations.Add(caMin);
}
}
}