...
C#
private void Form1_Load(object sender, EventArgs e)
{Wiki Markup // Clear previous data c1Chart1.ChartGroups\[0\].ChartData.SeriesList.Clear();
Wiki Markup // Add Data string\[\] ProductNames = \{ "Hand Mixer", "Stand Mixer", "Can Opener",
Wiki Markup "Toaster" ,"Blender" ,"Food Processor" ,"Slow Cooker" ,"Microwave"\}; int\[\] PriceX = \{ 80, 400, 20, 60, 150, 300, 130, 500 \};
// create single series for product priceWiki Markup C1.Win.C1Chart.ChartDataSeries ds1 = c1Chart1.ChartGroups\[0\].ChartData.SeriesList.AddNewSeries(); ds1.Label = "Price X";
//Use the CopyDataIn method of the ChartDataArray object to copy the X and Y value data into the data series ds1.X.CopyDataIn(ProductNames); ds1.Y.CopyDataIn(PriceX);Wiki Markup // Set chart type c1Chart1.ChartArea.Inverted = true; c1Chart1.ChartGroups\[0\].ChartType = C1.Win.C1Chart.Chart2DTypeEnum.Bar;
// Set axes titles c1Chart1.ChartArea.AxisX.Text = "Kitchen Electronics"; c1Chart1.ChartArea.AxisY.Text = "Price"; //Set format for the Y-axis annotation c1Chart1.ChartArea.AxisY.AnnoFormat = FormatEnum.NumericCurrency;
}线性图表指南
本章节介绍了如何创建带有符号的线性图表,它是默认的图表类型。一个线性图表是另外一种简单的用于展示数据关系的方式。
在这个示例里我们会创建一个带有符号的线性图表。我们只使用一个数据序列,因为只有一条线。这个线将用来表示一定时间范围内一个公司的利润的增长。在这个例子中的水平轴线,x 轴,代表年份值。例子中的垂直轴线,y 轴,代表以千美元为单位的利润值。
当你完成以下的步骤后,你将会创建如下图的出来。
在设计时创建带有符号的线性图表。
本任务假设您已经在您的窗体上添加了一个 C1Chart 控件。
设置图表类型
使用一个图表属性设计器来配置一个图表的第一个步骤是从可用图表类型中选择一个库类型。
...
C#
private void Form1_Load(object sender, EventArgs e)
{Wiki Markup //create data for the chart double\[\] xdata = \{ 2004, 2005, 2006, 2007 \}; double\[\] ydata = \{ 50, 100, 150, 200 \};
Wiki Markup //clear previous series c1Chart1.ChartGroups\[0\].ChartData.SeriesList.Clear();
//add one series to the chartWiki Markup C1.Win.C1Chart.ChartDataSeries ds = c1Chart1.ChartGroups\[0\].ChartData.SeriesList.AddNewSeries();
Wiki Markup //copy the x and y data ds.X.CopyDataIn(xdata); ds.Y.CopyDataIn(ydata); //set the chart type c1Chart1.ChartGroups\[0\].ChartType = C1.Win.C1Chart.Chart2DTypeEnum.XYPlot;
//create new font for the X and Y axes
Font f = new Font("Arial", 10, FontStyle.Bold); c1Chart1.ChartArea.Style.ForeColor = Color.DarkGray; c1Chart1.ChartArea.AxisX.Font = f; c1Chart1.ChartArea.AxisX.Text = "Year"; c1Chart1.ChartArea.AxisX.GridMajor.Visible = true; c1Chart1.ChartArea.AxisX.GridMajor.Color = Color.LightGray; c1Chart1.ChartArea.AxisY.Font = f; c1Chart1.ChartArea.AxisY.Text = "Profit (thousands of dollars)"; c1Chart1.ChartArea.AxisY.GridMajor.Visible = true; c1Chart1.ChartArea.AxisY.GridMajor.Color = Color.LightGray;
//modify line style appearance ds.LineStyle.Color = Color.LightPink; ds.LineStyle.Pattern = LinePatternEnum.Solid; ds.LineStyle.Thickness = 1;
//modify the symbol style appearance ds.SymbolStyle.Shape = SymbolShapeEnum.Box; ds.SymbolStyle.Color = Color.LightPink; ds.SymbolStyle.OutlineColor = Color.Black; ds.SymbolStyle.Size = 5; ds.SymbolStyle.OutlineWidth = 1; c1Chart1.ChartArea.PlotArea.BackColor = Color.White;
}饼状图表指南
本节将教您如何一步步地创建一个饼状图表。饼状图表用来表示简单值。不同于其他的
C1Chart 图表类型,饼状图表必须含有多于一个的序列以显示多个切片。如果仅有一个序列,那么饼状图表将会显示一个圆环而不会显示任何的切片。在本实例中,我们会创建有八个切片的饼状图表,所以我们会有八个序列,每个点对应一个序列,最终会有八个点。
下图展示了一个使用一个切片来代表一个商品种类的饼状图表。
以下将说明使用图表对象来在运行时和以编程方式来创建一个饼状图表的步骤。
在设计时创建一个饼状图表。
本任务假设您已经在您的窗体上添加了一个 C1Chart 控件。
设置图表类型
使用一个图表属性设计器来配置一个图表的第一个步骤是从可用图表类型中选择一个库类型。
...
private void Form1_Load(object sender, EventArgs e)
|
...
C#
private void Form1_Load(object sender, EventArgs e)
{Wiki Markup c1Chart1.ChartGroups\[0\].ChartData.SeriesList.AddNewSeries();
Wiki Markup //Declare the x and y variables as double to represent the x, y, y1, y2, and y3 values and assign the values double\[\] x = new double\[\] \{ 1, 2, 3, 4, 5 \}; double\[\] y_hi = new double\[\] \{ 8, 12, 10, 12, 15 \}; double\[\] y_low = new double\[\] \{ 20, 22, 19, 24, 25 \}; double\[\] y_open = new double\[\] \{ 10, 16, 17, 15, 23 \}; double\[\] y_close = new double\[\] \{ 16, 19, 15, 22, 18 \}; //copy the x, y, y1, y2, and y3 data into the chart group c1Chart1.ChartGroups\[0\].ChartData\[0\].X.CopyDataIn(x); c1Chart1.ChartGroups\[0\].ChartData\[0\].Y.CopyDataIn(y_hi); c1Chart1.ChartGroups\[0\].ChartData\[0\].Y1.CopyDataIn(y_low); c1Chart1.ChartGroups\[0\].ChartData\[0\].Y2.CopyDataIn(y_open); c1Chart1.ChartGroups\[0\].ChartData\[0\].Y3.CopyDataIn(y_close);
Wiki Markup //assign the candle chart to the chart type c1Chart1.ChartGroups\[0\].ChartType = C1.Win.C1Chart.Chart2DTypeEnum.Candle;
Wiki Markup //Make the rising candles transparent to show rising prices c1Chart1.ChartGroups\[0\].HiLoData.FillTransparent = true;
//Declare the color for the linesWiki Markup c1Chart1.ChartGroups\[0\].ChartData.SeriesList\[0\].LineStyle.Color = System.Drawing.Color.Red; //Increase the line thickness c1Chart1.ChartGroups\[0\].ChartData.SeriesList\[0\].LineStyle.Thickness = 2; c1Chart1.ChartGroups\[0\].ChartData.SeriesList\[0\].SymbolStyle.Size = 10;
}多图表指南
本主题将引导您以编程方式来一步步地在一个图表上添加一个 Bar 和 XYPlot 图表。图表使用条状图的 y-轴来表示平均的降雨量,X-轴线代表从五月到八月的月份字符串值。XYPlot 图表使用一个 y2-轴线来代表从五月到八月的每月的平均气温值,X-轴线代表从五月到八月的月份字符串值。
在您创建该图表之前下图用来展示该图表的效果。
1. 添加以下的代码来引入 C1.Win.C1Chart 命名空间。- Visual Basic
...
//input the data through the series collection
|
//customize axes |
...