Crosshair Shared tooltip on a line chart with multiple dynamic categories and 2 x axes

1 posts, 0 answers
  1. Curtis
    Curtis avatar
    1 posts
    Member since:
    Mar 2013

    Posted 21 Mar 2014 Link to this post

    I have a line chart in a MVC razer web app to which the user can add at runtime up to 5 categories. The chart also has 2 x axes, one that delineates time, the other that delineates dates. The tooltip has been appearing over the particular category line over which the mouse hovers. I want the crosshair functionality where a vertical line appears and one tooltip shows the values for all categories and cannot get it to work.

    I assume it has something to do with the fact I have 2 x axes, dynamically add categories at runtime, or both. Further, a y axis is added for each category that is added to the chart, though I assume the stuff going on with the y axes is not contributing to the problem, but I'm not certain of that.

    Below is the cshtml code for the chart. It differs from the original code only in regards to:
    1) The addition of .CategoryAxis(axis => axis.Crosshair(c => c.Visible(true)))
    2) The addition of .Shared(true) for the tooltip.

    I have not included any of the javascript/jQuery code that executes when a user adds a category, and I realize to solve this problem seeing that code may be necessary. Will provide on request.

    Attached is a screen shot of the chart after 5 categories have been added, showing how a tooltip appears only for the category over which the mouse hovers.

          .Series(series => series.ScatterLine(s => s.Local_TimeStamp, s => s.Value))
          .HtmlAttributes(new { @class = "multiPenChart" })
          .CategoryAxis(axis => axis.Crosshair(c => c.Visible(true)))
          .XAxis(x => x.Date()
                    .Labels(labels => labels.Visible(false).Format("HH:mm")))
          .XAxis(x => x.Date()
                    .Labels(labels => labels.Visible(false).Format("MM/dd")))
          .Tooltip(tooltip => tooltip
              .Template("<div class='ChartTooltip'>#= formatDate(value.x) # - #= value.y #</div>"))
          .Events(events => events.DataBound("onDataBound"))

Back to Top