Search code examples
c#asp.netchartstooltip

Box Plot Chart Tooltip Visibility


I have already created box plot chart in C# and add in the tooltip so that when user mouse over any box plot series on the chart, user can see tooltip appears showing values of the box plot series. However, no tooltip appear for box plot series of same value for all the 6 Y-values(max, min, avg, 25th percentile, 50th percentile, 75th percentile).

For example, if a box plot series got 15 as its max, min, avg, 25th percentile, 50th percentile and 75th percentile values, because it is same value throughout (a straight line), tooltip does not appear.

Current output:

Tooltip will appear when values are not the same for all 6 Y-values of a box plot series:

enter image description here Tooltip will not appear when values are the same for all 6 Y-values of a box plot series: enter image description here This is my code:

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;

Question: How to make tooltip appear for box plot series with same values for all 6 Y-values?

Thanks for any help.


Solution

  • Add Tooltip for Series[1] as well:

    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