添加文本,图像到asp.net图表控件

时间:2012-08-09 12:15:12

标签: asp.net data-visualization mschart linechart

我使用asp.net图表控件在我的网站上显示图表,下面是它的片段: line chart

问题是我想在每个点上添加文本和箭头线,所以例如在点(60,十月)上我想在此处写文本:投影最高和箭头图像。 是否有可能实现这样的事情,任何建议或帮助将受到高度赞赏,下面是我用来生成此图表的代码:

double[] yValues = { 15, 60, 12, 13 };
        string[] xValues = { "September", "October", "November", "December" };


        chart.Width = 500;
        chart.Height = 200;
        chart.BorderSkin.SkinStyle = BorderSkinStyle.FrameThin1;

        ChartArea ca = new ChartArea();
        ca.Name = "Default";
        ca.AxisX.LineColor = System.Drawing.ColorTranslator.FromHtml("#FEFEFE");
        ca.AxisX.LineWidth = 3;
        ca.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
        ca.AxisX.MajorGrid.Enabled = false;
        ca.AxisX.MajorTickMark.LineWidth = 2;
        ca.AxisX.LabelStyle.Format = "L";

        ca.AxisY.LineColor = System.Drawing.ColorTranslator.FromHtml("#FEFEFE");
        ca.AxisY.LineWidth = 3;
        ca.AxisY.MajorGrid.Enabled = true;
        ca.AxisY.MajorTickMark.LineWidth = 2;
        ca.AxisY.Title = "yaxis";

        chart.ChartAreas.Add(ca);

        Legend legend = new Legend();
        chart.Legends.Add(legend);
        Series series = new Series("Series1");
        series.IsValueShownAsLabel = false;
        series.MarkerStyle = MarkerStyle.Circle;
        series.BorderWidth = 5;
        series.ChartType = SeriesChartType.Line;

        series.ShadowOffset = 2;
        series.XValueType = ChartValueType.String;
        series.YValueType = ChartValueType.Double;
        series.Font = new System.Drawing.Font("Trebuchet MS", 8);
        series.BorderColor = System.Drawing.ColorTranslator.FromHtml("#33CCFF");
        series.Color = System.Drawing.ColorTranslator.FromHtml("#33CCFF");

        chart.Series.Add(series);
        chart.Series["Series1"].Points.DataBindXY(xValues, yValues);
        chart.DataManipulator.InsertEmptyPoints(1, System.Web.UI.DataVisualization.Charting.IntervalType.Days, "Series1");

1 个答案:

答案 0 :(得分:2)

您需要搜索最大的数据点并使用属性

datapoint.Label = "projection was highest";

最突出要点的最简单方法是使用datapoint.MarkerStyle属性。你可以画一个箭头,但我认为它不值得麻烦。