0

I've been searching for some sort of tutorial focusing on how tooltips to work, but have not had much luck.

I have a test project where I render a line chart with five data points. When I instantiate the Chart object I set IsMapEnabled = true. When I define the series I try to set the tool tip.

  private void DefineSeries() {
     var series = new Series();
     series.ToolTip = "#VALY";
     series.PostBackValue = "#Index";
     var x = new[] {0, 1, 2, 3, 4, 5};
     var y = new[] {0, 4, 5, 3, 7, 2};
     for ( int i = 0; i < x.Length; i++ ) {
         series.Points.Add( new DataPoint( x[ i ], y[ i ] ) );
     }
     series.ChartType = SeriesChartType.Line;
     DefineSeriesStyle( series );
     chart_.Series.Add( series );   
  }

The chart renders as expected, but a tooltip does not display when the mouse hovers over a data point. I am clearly missing a step somewhere, but I have no idea what it is.

EDIT: Code that shows the Action method and constructor for the chart view model and subsequent function call.

  public ActionResult CausedOutPoint() {
     var causedOut = new CausedOutViewModel();
     var path = Server.MapPath( "~" ) + "CausedOut.Png";
     causedOut.Chart.SaveImage( path, ChartImageFormat.Png );
     return File( path, "img/png" );
  }

  public CausedOutViewModel() {
     chart_ = new Chart {IsMapEnabled = true};
     chart_.PostPaint += chart__PostPaint;
     chart_.RenderType = RenderType.ImageMap;
     chart_.ID = "CausedOut";
     InitializeChart( chart_ );
     chart_.Width = new Unit( 1200, UnitType.Pixel );
     chart_.Height = new Unit( 800, UnitType.Pixel );
     CreateTitles();
  }

  private void InitializeChart( ) {
     DefineSeries();
     DefineChartArea();
  }
BrianM
  • 173
  • 3
  • 14
  • Did you set an ID for the `Chart`, as referenced in the accepted answer for [MSChart / Asp.net Charts dont show tooltips](http://stackoverflow.com/questions/9456506/mschart-asp-net-charts-dont-show-tooltips)? – Karl Anderson Aug 23 '13 at 15:56
  • I did see that during my searches. I tried it and still nothing. – BrianM Aug 23 '13 at 16:11

2 Answers2

0

You are doing something in DefineSeriesStyle that disables the tooltips. I have tested your method without the statement DefineSeriesStyle( series ); and the tooltips are shown.

For a comprehensive overview on tooltips, custom tooltips refer my previous answer for a similar question. Show tooltip in LineSeries WinForms Chart?

Community
  • 1
  • 1
Joe Vi
  • 473
  • 4
  • 10
  • I tried commenting out the `DefineSeriesStyle` and it still didn't work. The only thing I do in the method is set the series color, marker style, etc. I don't touch the tooltip properties (label or otherwise) at all. So I think this might point to how I am rendering the chart. I edited more code into the original post that shows the Action method, view model constructor, and the `InitializeChart` method. – BrianM Aug 26 '13 at 18:31
0

urns out my issue was that I was no rendering the map area for my chart. For those who run into a the same problem his the code that fixed my problem:

The controller

  public ActionResult CausedOutPoint() {
     var ms = (byte[])Session[ "MS" ];
     return File( ms, "img/png" );
  }

  public ActionResult CausedOutMap(string name)
  {

     var causedOut = new CausedOutViewModel();
     var ms = new MemoryStream();
     causedOut.Chart.SaveImage(ms, ChartImageFormat.Png);
     Session[ "MS" ] = ms.ToArray();
     return Content( causedOut.Chart.GetHtmlImageMap( name ) );
  }

Necessary Razor in the Index.csthml

    <img  src="@Url.Action("CausedOutPoint")" usemap="#CausedOut"/>
    @{
        Html.RenderAction("CausedOutMap", new { name = "causedOut"});
    }
BrianM
  • 173
  • 3
  • 14