Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

  • 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 price


    Wiki 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 chart


    Wiki 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)
{

Wiki Markup
// Set chart type  c1Chart1.ChartArea.Inverted = true;  c1Chart1.ChartGroups\[0\].ChartType = C1.Win.C1Chart.Chart2DTypeEnum.Pie;



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 \};



//get series collection


Wiki Markup
ChartDataSeriesCollection dscoll = c1Chart1.ChartGroups\[0\].ChartData.SeriesList;



//populate the series for (int i=0; i < PriceX.Length; i++)
{
ChartDataSeries series = dscoll.AddNewSeries();
//Add one point to show one pie series.PointData.Length = 1;


Wiki Markup
//Assign the prices to the Y Data series  series.Y\[0\] = PriceX\[i\];




Wiki Markup
//format the product name and product price on the legend  series.Label = string.Format("\{0\} (\{1:c\})", ProductNames\[i\], PriceX\[i\]);  \}



// show pie Legend c1Chart1.Legend.Visible = true; //add a title to the chart legend
c1Chart1.Legend.Text = "Product Unit Prices";
}


...

  • 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 lines


    Wiki 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
ChartDataSeriesCollection cdsc = cgroup.ChartData.SeriesList; cdsc.Clear(); //remove default data
//create the series object from the collection and add data ChartDataSeries cds = cdsc.AddNewSeries();

Wiki Markup
// Add Data for ChartGroup0, Bar chart  string\[\] MonthNames = \{ "March", "April", "May", "June", "July", "August" \};  double\[\] AvgPrecip = \{ 3.17, 3.01, 3.80, 4.12, 3.96, 3.38\};



//create a label for the Bar chart data series cds.Label = "Avg. Precip";

//Use the CopyDataIn method of the ChartDataArray object to copy the X and Y value data into the data series cds.X.CopyDataIn(MonthNames); cds.Y.CopyDataIn(AvgPrecip);

//create variable for chart area
C1.Win.C1Chart.Area carea = c1Chart1.ChartArea;
//Set axes titles for the ChartGroup0 (Bar) carea.AxisX.Text = "Month"; carea.AxisY.Text = "Avg. Precip (in)";

//create and add the data for the XY chart in Group1 ChartGroup cgroup2 = c1Chart1.ChartGroups.Group1; cgroup2.ChartType = Chart2DTypeEnum.XYPlot;

//input the bar chart data of group1 through the series collection
ChartDataSeriesCollection cdsc2 = cgroup2.ChartData.SeriesList;

//create the series object from the second collection and add data ChartDataSeries cds2 = cdsc2.AddNewSeries(); cds2.X.CopyDataIn(MonthNames);


Wiki Markup
cds2.Y.CopyDataIn(new double\[\] \{ 49.5, 60.7, 70.8, 79.1, 82.7, 81.1\});  cds2.Label = "Avg. High Temp";






//customize axes
//create new font for the X, Y and Y2 axes Font f = new Font("Arial", 10); carea.AxisX.Font = f; carea.AxisY.Font = f; carea.AxisX.ForeColor = Color.SteelBlue; carea.AxisY.ForeColor = Color.SteelBlue; carea.AxisY2.ForeColor = Color.SteelBlue; carea.AxisY2.Font = f;

//Set axes titles for the ChartGroup1 (XYPlot) carea.AxisY2.Text = "Avg. High Temp (F)";

//set axis bounds carea.AxisY.Min = 2.75; carea.AxisY2.Min = 30; carea.AxisY2.Max = 90; carea.AxisY.UnitMinor = .25;

//rotate the axis X annotation carea.AxisX.AnnotationRotation = 60;
//add legend c1Chart1.Legend.Visible = true;

//add header
c1Chart1.Header.Visible = true; c1Chart1.Header.Text = "Pittsburgh Spring and Summer Season";

//add visual Effects Style s = carea.Style;
s.ForeColor = Color.White;
s.BackColor = Color.LightBlue;
s.BackColor2 = Color.Azure;
s.GradientStyle = GradientStyleEnum.Radial; c1Chart1.ColorGeneration = ColorGeneration.Flow;
}

...