3

这是生成我的图表的代码:

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 值处设置标记的代码是什么?

4

1 回答 1

7

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


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];
访问DataPoint

于 2011-01-11T15:37:33.773 回答