当前位置: 首页>>代码示例>>C#>>正文


C# Chart.DataBind方法代码示例

本文整理汇总了C#中System.Windows.Forms.DataVisualization.Charting.Chart.DataBind方法的典型用法代码示例。如果您正苦于以下问题:C# Chart.DataBind方法的具体用法?C# Chart.DataBind怎么用?C# Chart.DataBind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.DataVisualization.Charting.Chart的用法示例。


在下文中一共展示了Chart.DataBind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveChart

        private static void SaveChart(List<double> requestTimes, TimeSpan totalTime, double minTime, double maxTime, double avgTime)
        {
            DataSet dataSet = new DataSet();
            DataTable dt = new DataTable();
            dt.Columns.Add("Seconds", typeof(int));
            dt.Columns.Add("RequestCount", typeof(int));

            Dictionary<int, int> timeTable = new Dictionary<int, int>();

            List<DataRow> rows = new List<DataRow>();
            List<int> intTimes = requestTimes.OrderBy(t => t).Select(t => (int)Math.Round(t/1000)).ToList();

            foreach (int time in intTimes)
            {
                DataRow row = rows.FirstOrDefault(r => ((int)r[0]) == time);

                if (row == null)
                {
                    row = dt.NewRow();
                    row[0] = time;
                    row[1] = 0;
                    rows.Add(row);
                }

                row[1] = ((int)row[1]) + 1;
            }

            rows.ForEach(r => dt.Rows.Add(r));

            dataSet.Tables.Add(dt);

            Chart chart = new Chart();
            chart.DataSource = dataSet.Tables[0];
            chart.Width = 900;
            chart.Height = 500;

            Series series = new Series();
            series.Name = "Serie1";
            series.Color = Color.FromArgb(220, 0, 27);
            series.ChartType = SeriesChartType.Column;
            series.ShadowOffset = 0;
            series.IsValueShownAsLabel = true;
            series.XValueMember = "Seconds";
            series.YValueMembers = "RequestCount";
            series.Font = new Font(series.Font.FontFamily, 10);
            chart.Series.Add(series);

            ChartArea ca = new ChartArea();
            ca.Name = "ChartArea1";
            ca.BackColor = Color.White;
            ca.BorderWidth = 0;
            ca.AxisX = new Axis();
            ca.AxisY = new Axis();
            ca.AxisX.Title = "Time (seconds)";
            Font f = ca.AxisX.TitleFont;
            ca.AxisX.TitleFont = new Font(f.FontFamily, 12, f.Style);
            ca.AxisY.Title = "Request count";
            ca.AxisY.TitleFont = ca.AxisX.TitleFont;
            ca.AxisX.MajorGrid.LineColor = Color.LightGray;
            ca.AxisY.MajorGrid.LineColor = ca.AxisX.MajorGrid.LineColor;
            chart.ChartAreas.Add(ca);

            chart.Titles.Add("Requests times");
            chart.Titles[0].Font = ca.AxisX.TitleFont;
            chart.Titles.Add(GetChartDescriptionString(totalTime, minTime, maxTime, avgTime));
            chart.Titles[1].Font = new Font(chart.Titles[1].Font.FontFamily, 10);

            chart.DataBind();

            int i = 0;
            string fileName = "";

            //loop until you find a free file name (in case multiple instances are running at the same time)
            do
            {
                fileName = string.Format("chart-{0}.png", i++);
            }
            while(File.Exists(fileName));

            chart.SaveImage(fileName, ChartImageFormat.Png);
        }
开发者ID:dland512,项目名称:loadrunnerx,代码行数:81,代码来源:Program.cs

示例2: chartdatatable

        private void chartdatatable(DataTable dt, Chart Chart1)
        {
            Chart1.Series.Clear();
            Chart1.DataSource = dt;
            string serieName = "";
            int amountofrows = Convert.ToInt32(dt.Rows.Count);
            List<string> xvals = new List<string>();
            List<double> yvals = new List<double>();

            foreach (DataColumn column in dt.Columns)
            {
                xvals.Add(column.ColumnName);

            }
            int i = 1;
            foreach (DataRow row in dt.Rows)
            {
                serieName = "Simulation" + i;
                Chart1.Series.Add(serieName);
                Chart1.Series[serieName].ChartType = SeriesChartType.Line;
                //       List<double> yvals = new List<double>();
                foreach (DataColumn column in dt.Columns)
                {
                    yvals.Add(Convert.ToDouble(row[column]));
                }
                try//add the newly created sereies...
                {
                    Chart1.Series[serieName].XValueType = ChartValueType.String;
                    Chart1.Series[serieName].YValueType = ChartValueType.Auto;
                    Chart1.Series[serieName].Points.DataBindXY(xvals.ToArray(), yvals.ToArray());
                    yvals.Clear();
                }
                catch (Exception)
                {

                    throw new InvalidOperationException("Kunde inte bind punkterna till Diagrammet");
                }

                i++;
            }

            Chart1.DataBind();
            Chart1.Visible = true;
        }
开发者ID:seanclogher,项目名称:Modelling-Tool,代码行数:44,代码来源:frmModellingTool.cs

示例3: BuildChart

        public void BuildChart(string fileName, IEnumerable<PieChartItem> data, PieChartContext context)
        {
            if (data == null || data.Count() == 0)
                throw new System.FormatException("There is not data to plot.");

            using (var targetChart = new Chart()) {

                ChartArea mainChartArea = new ChartArea("MainArea");
                targetChart.ChartAreas.Add(mainChartArea);
                targetChart.ChartAreas[0].Area3DStyle.Enable3D = context.Show3DStyle;

                ChartHelper.InitializeChart(targetChart, context.ImageSize);

                if (!string.IsNullOrWhiteSpace(context.Title)) {

                    targetChart.Titles.Add(new Title(context.Title, Docking.Top,
                                                     new System.Drawing.Font(context.TitleFontName,
                                                                             context.TitleFontSize,
                                                                             System.Drawing.FontStyle.Bold),
                                                                             context.TitleFontColor));
                }

                targetChart.Series.Add(context.Title);
                targetChart.Series[0].XValueMember = "Label";
                targetChart.Series[0].YValueMembers = "Value";
                targetChart.DataSource = data;

                targetChart.Series[0].IsVisibleInLegend = true;
                targetChart.Series[0].ChartType = SeriesChartType.Pie;

                targetChart.Series[0].LegendText = "#VALX";

                // https://technet.microsoft.com/en-us/library/dd239373.aspx
                switch (context.LabelStyle) {
                    case PieChartLabelStyle.None:
                        targetChart.Series[0].Label = string.Empty;
                        targetChart.Series[0].XValueMember = string.Empty;
                        break;
                    case PieChartLabelStyle.Value:
                        targetChart.Series[0].Label = "#VALY";
                        break;
                    case PieChartLabelStyle.Percent:
                        targetChart.Series[0].Label = "#PERCENT{P2}";
                        break;
                    case PieChartLabelStyle.ValuePercent:
                        targetChart.Series[0].Label = "#VALY / #PERCENT{P2}";
                        break;
                    case PieChartLabelStyle.Label:
                        targetChart.Series[0].Label = "#VALX";
                        break;
                    case PieChartLabelStyle.LabelValue:
                        targetChart.Series[0].Label = "#VALX (#VALY)";
                        break;
                    case PieChartLabelStyle.LabelPercent:
                        targetChart.Series[0].Label = "#VALX (#PERCENT{P2})";
                        break;
                    case PieChartLabelStyle.LabelValuePercent:
                        targetChart.Series[0].Label = "#VALX (#VALY / #PERCENT{P2})";
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("LabelStyle");
                }

                targetChart.Series[0].IsValueShownAsLabel = context.IsValueShownAsLabel;

                if (context.IsLabelOutside)
                    targetChart.Series[0]["PieLabelStyle"] = "Outside";

                System.Drawing.Color lineColor = context.LineColor;

                targetChart.ChartAreas[0].AxisX.LineColor =
                    targetChart.ChartAreas[0].AxisY.LineColor =
                        targetChart.ChartAreas[0].AxisX.InterlacedColor =
                            targetChart.ChartAreas[0].AxisY.InterlacedColor =
                                targetChart.ChartAreas[0].AxisX.MajorGrid.LineColor =
                targetChart.ChartAreas[0].AxisY.MajorGrid.LineColor =
                    targetChart.ChartAreas[0].AxisX.TitleForeColor =
                        targetChart.ChartAreas[0].AxisY.TitleForeColor =
                            targetChart.ChartAreas[0].AxisX.MajorTickMark.LineColor =
                                targetChart.ChartAreas[0].AxisY.MajorTickMark.LineColor = lineColor;

                ChartHelper.AddLegend(targetChart, ChartHelper.ParseLegendStyle(context.LegendStyle));

                targetChart.DataBind();

                targetChart.SaveImage(fileName, ChartImageFormat.Png);
            }
        }
开发者ID:FerHenrique,项目名称:Owl,代码行数:88,代码来源:PieChartCreator.cs

示例4: BuildChart

        public void BuildChart(string fileName, DataTable data, LineChartContext context)
        {
            if (data == null || data.Columns.Count == 0)
                throw new System.FormatException("There is not data to plot.");

            System.Drawing.Color[] colors = ChartHelper.GetColors();
            if (data.Columns.Count - 1 > colors.Length)
                throw new IndexOutOfRangeException("We don't have enough colors to render this chart.");

            using (var targetChart = new Chart()) {

                ChartArea mainChartArea = new ChartArea("MainArea");
                targetChart.ChartAreas.Add(mainChartArea);

                ChartHelper.InitializeChart(targetChart, context.ImageSize);

                if (!string.IsNullOrWhiteSpace(context.Title)) {

                    targetChart.Titles.Add(new Title(context.Title, Docking.Top,
                                                     new System.Drawing.Font(context.TitleFontName,
                                                                             context.TitleFontSize,
                                                                             System.Drawing.FontStyle.Bold),
                                                                             context.TitleFontColor));
                }

                targetChart.DataSource = data;

                string xval = data.Columns[0].ToString();

                for (int i = 1; i < data.Columns.Count; i++) {

                    string columnName = data.Columns[i].ColumnName;

                    targetChart.Series.Add(columnName);

                    // Using column name as the legend
                    targetChart.Series[i - 1].Name = columnName;
                    targetChart.Series[i - 1].LegendText = columnName;

                    targetChart.Series[i - 1].XValueMember = xval;
                    targetChart.Series[i - 1].XValueType = ChartHelper.ParseCharValueType(context.XValueType);
                    targetChart.Series[i - 1].YValueMembers = data.Columns[i].ToString();
                    targetChart.Series[i - 1].ChartType = SeriesChartType.Line;

                    targetChart.Series[i - 1].Color = colors[i - 1];
                }

                System.Drawing.Color lineColor = context.LineColor;

                targetChart.ChartAreas[0].AxisX.LineColor =
                    targetChart.ChartAreas[0].AxisY.LineColor =
                        targetChart.ChartAreas[0].AxisX.InterlacedColor =
                            targetChart.ChartAreas[0].AxisY.InterlacedColor =
                                targetChart.ChartAreas[0].AxisX.MajorGrid.LineColor =
                targetChart.ChartAreas[0].AxisY.MajorGrid.LineColor =
                    targetChart.ChartAreas[0].AxisX.TitleForeColor =
                        targetChart.ChartAreas[0].AxisY.TitleForeColor =
                            targetChart.ChartAreas[0].AxisX.MajorTickMark.LineColor =
                                targetChart.ChartAreas[0].AxisY.MajorTickMark.LineColor = lineColor;

                ChartHelper.AddLegend(targetChart, ChartHelper.ParseLegendStyle(context.LegendStyle));

                targetChart.DataBind();

                targetChart.SaveImage(fileName, ChartImageFormat.Png);
            }
        }
开发者ID:FerHenrique,项目名称:Owl,代码行数:67,代码来源:LineChartCreator.cs

示例5: buttonGenerateChart_Click


//.........这里部分代码省略.........
            if (tableLayoutInformation == null)
                return;

            DataGridView dataGridViewInformation = (DataGridView)tableLayoutInformation.Controls[0];
            if (dataGridViewInformation == null)
                return;

            DataTable dataTable = (DataTable)dataGridViewInformation.DataSource;
            if (dataTable == null)
                return;

            if (string.IsNullOrEmpty(comboBoxChartColumn.Text) || string.IsNullOrEmpty(comboBoxChartType.Text))
                return;

            string columnName = "";
            foreach (DataColumn dataColumn in dataTable.Columns) {
                if (dataColumn.DataType == typeof(DateTime))
                    columnName = dataColumn.ColumnName;
            }

            //Titles
            Title titleAts = new Title();
            titleAts.Alignment = ContentAlignment.TopCenter;
            titleAts.Name = "chartTitleAts";
            titleAts.Text = "Advanced Technologies and Solutions";

            Title titleChart = new Title();
            titleChart.Alignment = ContentAlignment.TopCenter;
            titleChart.Name = "chartTitle";
            titleChart.Text = tabControl.TabPages[0].Name + " (" + comboBoxChartType.Text + " Chart)";
            titleChart.TextStyle = TextStyle.Shadow;
            titleChart.Font = new Font("Calibri", 16, FontStyle.Bold);

            //Chart
            Chart chart = new Chart();
            chart.Titles.Add(titleAts);
            chart.Titles.Add(titleChart);
            chart.Dock = DockStyle.Fill;
            chart.BackColor = Color.FromName(comboBoxBackground.Text);
            chart.DataSource = dataTable;
            chart.AntiAliasing = AntiAliasingStyles.All;
            chart.TextAntiAliasingQuality = TextAntiAliasingQuality.High;
            chart.Text = dataGridViewInformation.Name;

            //ContextMenuStrip
            ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
            contextMenuStrip.Name = "Chart";
            ToolStripItem toolStripItemChartSaveAsImage = contextMenuStrip.Items.Add("Save as image");
            toolStripItemChartSaveAsImage.Click += toolStripItemChartSaveAsImage_Click;
            chart.ContextMenuStrip = contextMenuStrip;

            //ChartLegends
            chart.Legends.Clear();
            chart.Legends.Add("Legend");
            chart.Legends["Legend"].Name = comboBoxChartColumn.Text;

            //ChartArea
            ChartArea chartArea = new ChartArea();
            chartArea.Name = columnName;
            chartArea.BackGradientStyle = GradientStyle.VerticalCenter;
            chartArea.BackColor = Color.FromName(comboBoxBackground.Text);

            //ChartAreaX
            chartArea.AxisX.Title = columnName;
            chartArea.AxisX.TitleFont = new Font("calibri", 16, FontStyle.Bold);
            chartArea.AxisX.LabelStyle.Format = "yyyy/MM/dd HH:mm:ss";
            chartArea.AxisX.TitleAlignment = StringAlignment.Center;
            chartArea.AxisX.MajorGrid.LineColor = Color.Transparent;
            chartArea.AxisX.Name = columnName;
            chartArea.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep90;
            chartArea.AxisX.ScaleView.Zoomable = true;

            //ChartAreaY
            chartArea.AxisY.Title = comboBoxChartColumn.Text;
            chartArea.AxisY.MajorGrid.LineColor = Color.LightGray;
            chartArea.AxisY.TitleFont = new Font("calibri", 16, FontStyle.Bold);
            chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.DashDotDot;
            chartArea.AxisY.Name = comboBoxChartColumn.Text;
            chartArea.AxisY.ScaleView.Zoomable = true;

            chart.ChartAreas.Add(chartArea);
            chart.MouseWheel += chart_MouseWheel;

            Series series = new Series(comboBoxChartColumn.Text);
            series.ChartType = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), comboBoxChartType.Text, true);
            series.XValueMember = columnName;
            series.YValueMembers = comboBoxChartColumn.Text;
            series.Color = Color.FromName(comboBoxSeries.Text);
            series.BorderWidth = 5;

            chart.Series.Add(series);

            chart.DataBind();

            FormChart formChart = new FormChart();
            formChart.Controls.Add(chart);
            formChart.Text = tabControl.TabPages[0].Name;
            formChart.StartPosition = FormStartPosition.CenterParent;
            formChart.Show();
        }
开发者ID:rhalf,项目名称:AtsTqatProReportingTool,代码行数:101,代码来源:FormMain.cs


注:本文中的System.Windows.Forms.DataVisualization.Charting.Chart.DataBind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。