MScharts 图表:覆盖列/条形值

发布于 2024-12-11 01:26:34 字数 1367 浏览 0 评论 0原文

好吧,这可能是一个新问题,但我几天前才开始编程。 因此,我从 MScharts 中获取了一个示例图表,它是在运行时动态创建的图表,代码如下:

        private void DynamicChartCreation_Load(object sender, System.EventArgs e)
    {
        // Create a Chart
        Chart1 = new Chart();

        // Create Chart Area
        ChartArea chartArea1 = new ChartArea();

        // Add Chart Area to the Chart
        Chart1.ChartAreas.Add(chartArea1);

        // Create a data series
        Series series1 = new Series();
        Series series2 = new Series();

        // Add data points to the first series
        series1.Points.Add(34);

        // Add data points to the second series
        series2.Points.Add(14);

        // Add series to the chart
        Chart1.Series.Add(series1);
        Chart1.Series.Add(series2);

        // Set chart control location
        Chart1.Location = new System.Drawing.Point(16, 48);

        // Set Chart control size
        Chart1.Size = new System.Drawing.Size(360, 260);

        // Add chart control to the form
        this.Controls.AddRange(new System.Windows.Forms.Control[] { this.Chart1 });

    }

它是一个柱形图,我希望能够通过组合框动态更改列值。 问题是如何覆盖现有的旧值?

我用 Series.point.add 尝试过,如下所示:

                Chart1.Series["Series1"].Points.AddY(comboBox_value);

但它不是将值应用于第一个 series1 列,而是创建另一个列,并在其旁边添加新值。

任何帮助将不胜感激,谢谢。

Ok this might be a newb question but I've only been programming since a few days.
So I took an example chart from MScharts that is a dynamically created graph during run-time, code is as follows:

        private void DynamicChartCreation_Load(object sender, System.EventArgs e)
    {
        // Create a Chart
        Chart1 = new Chart();

        // Create Chart Area
        ChartArea chartArea1 = new ChartArea();

        // Add Chart Area to the Chart
        Chart1.ChartAreas.Add(chartArea1);

        // Create a data series
        Series series1 = new Series();
        Series series2 = new Series();

        // Add data points to the first series
        series1.Points.Add(34);

        // Add data points to the second series
        series2.Points.Add(14);

        // Add series to the chart
        Chart1.Series.Add(series1);
        Chart1.Series.Add(series2);

        // Set chart control location
        Chart1.Location = new System.Drawing.Point(16, 48);

        // Set Chart control size
        Chart1.Size = new System.Drawing.Size(360, 260);

        // Add chart control to the form
        this.Controls.AddRange(new System.Windows.Forms.Control[] { this.Chart1 });

    }

It is a column chart and I want to be able to change the column values dynamically via a combobox.
The question is how do I overwrite the existing old values?

I tried it with Series.point.add like this:

                Chart1.Series["Series1"].Points.AddY(comboBox_value);

But instead of applying the value to the first series1 column, it creates another column with the new value right next to it.

Any help would be appreciated, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2024-12-18 01:26:35

我在我的项目中为axix“X”进行了自定义,我将代码粘贴到这里,供您参考......
它在我的环境中运行良好...请在您的环境中检查它。

protected void SpiLineAreaChart_Customize(object sender, EventArgs e)
{
    foreach (ChartArea area in ((Chart)sender).ChartAreas) {
        foreach (Axis axis in area.Axes) {
            if (axis.Name.StartsWith("X")) {
                foreach (CustomLabel label in axis.CustomLabels) {
                    counter = counter + 1;
                }
                lastpoint = counter;
                midpoint = counter / 2;
                for (int i = 0; i <= counter - 1; i++) {
                    if (i == 0) {
                        axis.CustomLabels(i).Text = MonthVal;
                    } else if (i == midpoint - 1) {
                        StartDate = StartDate.AddDays(31);
                        strstartdate = StartDate.ToString("MMM");
                        axis.CustomLabels(i).Text = strstartdate;
                    } else if (i == lastpoint - 1) {
                        StartDate = StartDate.AddDays(31);
                        strstartdate = StartDate.ToString("MMM");
                        axis.CustomLabels(i).Text = strstartdate;
                    } else {
                        axis.CustomLabels(i).Text = "";
                    }
                }

            }
        }
    }
}

I did customize in my project for axix "X", I paste code here, for your reference...
It's working fine in my environment... Please, check it in your environment.

protected void SpiLineAreaChart_Customize(object sender, EventArgs e)
{
    foreach (ChartArea area in ((Chart)sender).ChartAreas) {
        foreach (Axis axis in area.Axes) {
            if (axis.Name.StartsWith("X")) {
                foreach (CustomLabel label in axis.CustomLabels) {
                    counter = counter + 1;
                }
                lastpoint = counter;
                midpoint = counter / 2;
                for (int i = 0; i <= counter - 1; i++) {
                    if (i == 0) {
                        axis.CustomLabels(i).Text = MonthVal;
                    } else if (i == midpoint - 1) {
                        StartDate = StartDate.AddDays(31);
                        strstartdate = StartDate.ToString("MMM");
                        axis.CustomLabels(i).Text = strstartdate;
                    } else if (i == lastpoint - 1) {
                        StartDate = StartDate.AddDays(31);
                        strstartdate = StartDate.ToString("MMM");
                        axis.CustomLabels(i).Text = strstartdate;
                    } else {
                        axis.CustomLabels(i).Text = "";
                    }
                }

            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文