Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In order to bind the chart, I need both X and Y values which i am getting as Year and Rate (suppose 2014 and 2345689.22).I just want to change all the rates from string(after getting from database) to Words and want to show them in Tooltip.

I am Binding Tooltip with the help of #VALX and #VALY.
Here is my code :
CSS
Chart1.Series[0].XValueMember = "Year";
Chart1.Series[0].YValueMembers = "Rate";
Chart1.Series[0].ToolTip = "Year : #VALX \nRate : #VALY ";
Chart1.Series[0].LabelToolTip = "Year : #VALX \nRate : #VALY ";

Is anyhing Possible to convert this #VALY to Words so that all label's Tooltip would change.
Posted
Comments
CHill60 20-Aug-15 10:29am    
You were already given 3 solutions to this on your earlier post How to Convert Column Chart's #VALY from Int to String[^] - 2 of which you accepted.
Dipti Dhiman 3 21-Aug-15 8:56am    
The answers accepted in my past question were applicable if someone wants to convert number in words from database. Hence that were accepted.
But You can check my New Question, it is about the conversion after fetching the number from database and convert it to word in page.
In Chart, #VALY is giving all Y member values, and we can't convert it into Int since it works after data binding.(i.e. ConvertNumberToWord(Convert.ToInt32("#VALY")) gives #VALY and not converted to int)
Also, we cannot apply Loop because Chart Bind only once, hence accepting last converted word as tooltip for all labels of chart.

Yes, it is possible. Use String.Format[^] function:

C#
Chart1.Series[0].ToolTip = string.Format("Year : {0} \nRate : {1} ", xValueFromDataBase, yValueFromDataBase);
Chart1.Series[0].LabelToolTip = string.Format("Year : {0} \nRate : {1} ", xValueFromDataBase, yValueFromDataBase);


In case you want to display words instead of numeric values, please see the answers to your past question[^].
 
Share this answer
 
v2
Comments
Dipti Dhiman 3 21-Aug-15 8:57am    
Thank You Sir. But This Code didn't Worked for me.
Maciej Los 23-Aug-15 15:35pm    
What does not work for you?
Problem Solved
1.)Using Class :
C#
public string NumberToWords(int number)
   {
       if (number == 0)
           return "zero";

       if (number < 0)
           return "(Minus) " + NumberToWords(Math.Abs(number));

       string words = "";

       if ((number / 100000) > 0)
       {
           words += NumberToWords(number / 100000) + " lakh ";
           number %= 100000;
       }

       if ((number / 1000) > 0)
       {
           words += NumberToWords(number / 1000) + " thousand ";
           number %= 1000;
       }

       if ((number / 100) > 0)
       {
           words += NumberToWords(number / 100) + " hundred ";
           number %= 100;
       }

       if (number > 0)
       {
           if (words != "")
               words += "and ";

           var unitsMap = new[] { "Zero", "One", "Two",                     "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
           var tensMap = new[] { "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };

           if (number < 20)
               words += unitsMap[number];
           else
           {
               words += tensMap[number / 10];
               if ((number % 10) > 0)
                   words += "-" + unitsMap[number % 10];
           }
       }



2.)and using it in code as :


 for (int cnt = 0; cnt < Chartgpmreport.Series[0].Points.Count; cnt++)
{
Chart1.Series[0].Points[cnt].ToolTip = "Date : #VALX \nRate (INR) : #VALY \nRate(In Words) : " + converter.NumberToWords(Convert.ToInt32(db.dt.Rows[cnt][0]));
Chart1.Series[0].Points[cnt].LabelToolTip = "Date : #VALX \nRate (INR) : #VALY \nRate(In Words) : " + converter.NumberToWords(Convert.ToInt32(db.dt.Rows[cnt][0]));
}
return words;
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900