2013-08-23 111 views
0

我一直在尋找某種教程,重點討論工具提示如何工作,但沒有多少運氣。如何使鼠標懸停在數據點上時顯示工具提示

我有一個測試項目,我用五個數據點渲染折線圖。當我實例化Chart對象時,我設置了IsMapEnabled = true。當我定義系列時,我嘗試設置工具提示。

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

該圖表按預期呈現,但鼠標懸停在數據點上時不顯示工具提示。我顯然錯過了某個步驟,但我不知道它是什麼。

編輯:顯示圖表視圖模型和後續函數調用的Action方法和構造函數的代碼。

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(); 
    } 
+0

必要剃刀你設置一個ID爲'圖表',如在[MSChart/Asp.net圖表不顯示工具提示](http://stackoverflow.com/questions/9456506/mschart-asp-net-charts-dont-show-tooltips )? –

+0

我在搜索過程中看到了這一點。我試了一下,仍然沒有。 – BrianM

回答

0

嗯,我的問題是,我沒有渲染地圖區域爲我的圖表。對於那些誰碰上了同樣的問題,他的代碼,固定我的問題:

控制器

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

Index.csthml

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

您正在做的事情在DefineSeriesStyle,禁用工具提示。我已經測試了您的方法,但沒有顯示DefineSeriesStyle(series);並顯示工具提示。

有關工具提示的全面概述,自定義工具提示參考我以前的答案,以獲得類似問題。 Show tooltip in LineSeries WinForms Chart?

+0

我試着評論'DefineSeriesStyle',它仍然沒有工作。我在該方法中唯一做的是設置系列顏色,標記樣式等。我根本不觸摸工具提示屬性(標籤或其他)。所以我認爲這可能指向我如何渲染圖表。我將更多代碼編輯到顯示Action方法,視圖模型構造函數和'InitializeChart'方法的原始文章中。 – BrianM

相關問題