سؤال

I am using Visual Studio 2010 and WFC to create a point graph of data. To create my chart I have a datatable with 3 different columns; these are Date, Value and Serial. This table is generated dynamically off of an SQL query and then I plot the Date on the x axis and Value on the y axis. What I am trying to achieve is that when the mouse is over a point on the chart then a tool tip shows the Date, Value and the unique Serial relating to these values. At the moment I am using

myChart.Series["mySeries"].ToolTip = "XValue = #VALY \r\nDate = #VALX{d}";

however obviously this does not show the serial number against these values. I tried using a ToolTip event however had some problems when trying to convert from datapoint in pixels to an exact plot on the graph. I hope this question makes sense.

هل كانت مفيدة؟

المحلول

I solved the problem, with thank to @vikas. Rather than try to assign a generic tool tip I have assigned an individual tool tip for each point.

        int points = 0;

        //For every row in the values table, plot the date against the variable value
        foreach (DataRow row in Values.Rows)
        {
            myChart.Series[Variable].Points.AddXY(Convert.ToDateTime(row["Date"].ToString()), row["Variable"].ToString());               
            myChart.Series[Variable].Points[points].ToolTip = Variable + " = #VALY \r\nDate = #VALX{d} \r\nSerial = " + row["Serial"].ToString();
            points += 1;
        }

So the counter starts at 0 then for every row in the datatable Values 1 is added to the number of points and a Unique ToolTip is assigned for each point individually.

نصائح أخرى

just for Idea

For i As Integer = 0 To dt.Rows.Count - 1
                    StrSeries = Convert.ToString(dt.Rows(i)("Engage_Title"))
                    ChartRecentActivities.Series.Add(StrSeries)
                    ChartRecentActivities.Series(StrSeries).ChartType = SeriesChartType.Line
                    ChartRecentActivities.Series(StrSeries).MarkerStyle = MarkerStyle.Circle
                    ChartRecentActivities.Series(StrSeries).MarkerSize = 7
                    ChartRecentActivities.Series(StrSeries).BorderWidth = 3
                    ChartRecentActivities.Series(StrSeries).ShadowOffset = 2
                    ChartRecentActivities.Series(StrSeries).Legend = "Default"
                    ChartRecentActivities.Series(StrSeries).LegendText = StrSeries
                    ChartRecentActivities.Series(StrSeries).LegendToolTip = StrSeries
                    ChartRecentActivities.Series(StrSeries).ToolTip = StrSeries

                    For j As Integer = 0 To ChartRecentActivities.ChartAreas(0).Axes(0).CustomLabels.Count - 1
                        dv.RowFilter = "Engage_Title = '" & StrSeries & "' AND Transaction_Date = '" & ChartRecentActivities.ChartAreas(0).Axes(0).CustomLabels(j).Text & "'"
                        If (dv.Count > 0) Then
                            dblPoint = Convert.ToDouble(dv.Item(0)(0))
                        Else
                            dblPoint = 0
                        End If
                        ChartRecentActivities.Series(StrSeries).Points.Add(dblPoint)
                        ChartRecentActivities.Series(StrSeries).Points(j).ToolTip = StrSeries & " = " & dblPoint.ToString()
                    Next
                Next

look at the last line

ChartRecentActivities.Series(StrSeries).Points(j).ToolTip = StrSeries & " = " & dblPoint.ToString()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top