在 MSChart 上的特定 X 值处设置标记

发布于 2024-10-10 17:05:04 字数 1585 浏览 2 评论 0原文

以下是生成图表的代码:

System.Web.UI.DataVisualization.Charting.Chart Chart2 = new System.Web.UI.DataVisualization.Charting.Chart();
                Chart2.Width = 350;
                Chart2.Height = 350;
                Chart2.RenderType = RenderType.ImageTag;

                Chart2.Palette = ChartColorPalette.BrightPastel;
                Chart2.ChartAreas.Add("Series 1");
                Chart2.ChartAreas["Series 1"].BackColor = System.Drawing.Color.Transparent;

                // create a couple of series  
                Chart2.Series.Add("Series");

                // databinding
                Chart2.DataSource = pointCollection;
                Chart2.ChartAreas[0].AxisX.Title = "Date";
                Chart2.ChartAreas[0].AxisY.Title = "Future Exposure Amount";
                Chart2.Series[0].ChartType = SeriesChartType.Line;
                Chart2.Series[0].XValueMember = "ExposureDate";
                Chart2.Series[0].XValueType = ChartValueType.Date;
                Chart2.Series[0].YValueMembers = "MaximumExposure";

                Chart2.BackColor = System.Drawing.Color.FromArgb(211, 223, 240); //"#D3DFF0"
                Chart2.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
                Chart2.BackGradientStyle = GradientStyle.TopBottom;

                // Render chart control  
                Chart2.Page = this;

                Page.Response.Clear();

                HtmlTextWriter writer = new HtmlTextWriter(Page.Response.Output);
                Chart2.RenderControl(writer);

在图表上的某个 X 值处设置标记的代码是什么?

Here is the code that generates my chart:

System.Web.UI.DataVisualization.Charting.Chart Chart2 = new System.Web.UI.DataVisualization.Charting.Chart();
                Chart2.Width = 350;
                Chart2.Height = 350;
                Chart2.RenderType = RenderType.ImageTag;

                Chart2.Palette = ChartColorPalette.BrightPastel;
                Chart2.ChartAreas.Add("Series 1");
                Chart2.ChartAreas["Series 1"].BackColor = System.Drawing.Color.Transparent;

                // create a couple of series  
                Chart2.Series.Add("Series");

                // databinding
                Chart2.DataSource = pointCollection;
                Chart2.ChartAreas[0].AxisX.Title = "Date";
                Chart2.ChartAreas[0].AxisY.Title = "Future Exposure Amount";
                Chart2.Series[0].ChartType = SeriesChartType.Line;
                Chart2.Series[0].XValueMember = "ExposureDate";
                Chart2.Series[0].XValueType = ChartValueType.Date;
                Chart2.Series[0].YValueMembers = "MaximumExposure";

                Chart2.BackColor = System.Drawing.Color.FromArgb(211, 223, 240); //"#D3DFF0"
                Chart2.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
                Chart2.BackGradientStyle = GradientStyle.TopBottom;

                // Render chart control  
                Chart2.Page = this;

                Page.Response.Clear();

                HtmlTextWriter writer = new HtmlTextWriter(Page.Response.Output);
                Chart2.RenderControl(writer);

What is the code to set a marker at a certain X-Value on the chart?

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

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

发布评论

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

评论(1

没有心的人 2024-10-17 17:05:04

您可以逐点设置标记属性,例如,


double interestingValue = 12.34;
foreach (var pt in Chart2.Series[0].Points)
{
    if (pt.XValue == interestingValue)
    {
        pt.MarkerColor = System.Drawing.Color.Red;
        pt.MarkerSize = 5;
        pt.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
    }
}

XValues 将来自您绑定到的数据,即pointCollection 变量。

如果 pointCollection 的“ExposureDate”中有日期,您可能最好直接访问该日期以查找所需的日期,然后使用

var pt = Chart2.Series[0].Points[interestingIndex];

to access the DataPoint

You can set the Marker properties on a point by point basis, e.g.


double interestingValue = 12.34;
foreach (var pt in Chart2.Series[0].Points)
{
    if (pt.XValue == interestingValue)
    {
        pt.MarkerColor = System.Drawing.Color.Red;
        pt.MarkerSize = 5;
        pt.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
    }
}

The XValues will come from the data you bound to, the pointCollection variable.

If there are dates in the "ExposureDate" of the pointCollection you may be better accessing that directly to find the Date you want, and then using

var pt = Chart2.Series[0].Points[interestingIndex];


to access the DataPoint

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