如何使用C#向BoxPlot图表添加工具提示

时间:2015-10-30 05:45:39

标签: javascript c# asp.net charts tooltip

我已经动态创建了箱形图,但是想在箱形图中添加工具提示,这样当用户将鼠标悬停在箱形图系列上时,箱形图系列值将显示在工具提示。

这是我创建箱形图表的代码:

                        Chart Chart1= new Chart();
                        Chart1.DataSource = dt;
                        Chart1.Width = 800;
                        Chart1.Height = 490;

                        Chart1.Series.Add(new Series());
                        Chart1.Series[0].ChartType = SeriesChartType.BoxPlot;
                        Chart1.Series.Add(new Series());
                        Chart1.Series[1].ChartType = SeriesChartType.Point;
                        List<object> List1 = dt.AsEnumerable().ToList<object>();

                        int Chart1_AVG = 0;
                        int Chart1_POINTINDEX = 0;

                        foreach (DataRow row in dt.Rows)
                        {
                            Chart1_AVG = (int)row["AVG"];

                            Chart1.Series[0].Points.AddXY(row["CUSTOMER"], new object[] { row["MIN"], row["MAX"], row["25TH_PCT_NUMBER"], row["75TH_PCT_NUMBER"], row["50TH_PCT_NUMBER"], row["AVG"] });
                            Chart1_POINTINDEX = Chart1.Series[1].Points.AddXY(row["CUSTOMER"], new object[] { row["AVG"] });

                            if ((Chart1_AVG >= AvgMinColorGreen) && (Chart1_AVG <= AvgMaxColorGreen))
                            {
                                Chart1.Series[1].Points[Chart1_POINTINDEX].MarkerColor = Color.Green;
                            }
                            else if ((Chart1_AVG >= AvgMinColorYellow) && (Chart1_AVG <= AvgMaxColorYellow))
                            {
                                Chart1.Series[1].Points[Chart1_POINTINDEX].MarkerColor = Color.Orange;
                            }
                            else if ((Chart1_AVG >= AvgMinColorRed) && (Chart1_AVG <= AvgMaxColorRed))
                            {
                                Chart1.Series[1].Points[Chart1_POINTINDEX].MarkerColor = Color.Red;
                            }
                        }
                        Chart1.Series[0]["BoxPlotShowMedian"] = "false"; //hide the average point

                        //create chartareas
                        ChartArea ca= new ChartArea();

                        //databind
                        Chart1.DataBind();
                        Chart1.Visible = true;

                        panel.Controls.Add(Chart1);

请帮助我,谢谢。

1 个答案:

答案 0 :(得分:0)

使用此

Chart1.Series[0].ToolTip = "#VAL"

其他可能的工具提示是LegendToolTip,LabelToolTip ......

有关关键字,请参阅https://msdn.microsoft.com/de-de/library/vstudio/dd456687%28v=vs.110%29.aspx