方框图工具提示可见性

时间:2015-11-12 05:57:08

标签: c# asp.net charts tooltip

我已经在C#中创建了箱形图,并在工具提示中添加,以便当用户将鼠标悬停在图表上的任何箱形图系列上时,用户可以看到工具提示显示的箱形图系列的值。但是,对于所有6个Y值(最大值,最小值,平均值,第25百分位数,第50百分位数,第75百分位数),相同值的箱形图系列不会显示工具提示。

例如,如果一个箱形图系列得到15作为其最大值,最小值,平均值,第25百分位数,第50百分位数和第75百分位数值,因为它是相同的值(直线),工具提示不会出现。

当前输出:

当箱形图系列的所有6个Y值的值不相同时,将显示工具提示:

enter image description here 当箱形图系列的所有6个Y值的值相同时,不会显示工具提示: enter image description here 这是我的代码:

Chart chart1= new Chart();
chart1.DataSource = dt;

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["DESC"], 
        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["DESC"], new object[] { row["AVG"] });
    chart1.Series[0].Points[chart1_POINTINDEX].ToolTip = "Description:" + (string)row["DESC"] + 
                                    System.Environment.NewLine + 
                                    "25th Percentile:" + (int)row["25TH_PCT_NUMBER"] + 
                                    System.Environment.NewLine + 
                                    "50th Percentile:" + (int)row["50TH_PCT_NUMBER"] + 
                                    System.Environment.NewLine + 
                                    "75th Percentile:" + (int)row["75TH_PCT_NUMBER"] + 
                                    System.Environment.NewLine + 
                                    "Maximum:" + (int)row["MAX"] + 
                                    System.Environment.NewLine + 
                                    "Average:" + (int)row["AVG"] + 
                                    System.Environment.NewLine + 
                                    "Minimum:" + (int)row["MIN"];

    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;
    }
}

//create chartareas
ChartArea ca= new ChartArea();
ca.AxisX = new Axis();
ca.AxisX.MajorGrid.Enabled = false;
ca.AxisY = new Axis();
ca.AxisY.MajorGrid.Enabled = false;
chart1.ChartAreas.Add(ca);

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

问题:如何为所有6个Y值的相同值的箱形图系列显示工具提示?

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

Tooltip添加Series[1]

chart1.Series[1].Points[chart1_POINTINDEX].ToolTip = "Description:" + (string)row["DESC"] +
                            System.Environment.NewLine +
                            "25th Percentile:" + (int)row["25TH_PCT_NUMBER"] +
                            System.Environment.NewLine +
                            "50th Percentile:" + (int)row["50TH_PCT_NUMBER"] +
                            System.Environment.NewLine +
                            "75th Percentile:" + (int)row["75TH_PCT_NUMBER"] +
                            System.Environment.NewLine +
                            "Maximum:" + (int)row["MAX"] +
                            System.Environment.NewLine +
                            "Average:" + (int)row["AVG"] +
                            System.Environment.NewLine +
                            "Minimum:" + (int)row["MIN"];

enter image description here