Hello,
I am currently working with the WinChart and I am trying to show quotes information in a line chart. The information itself is shown fine but now I want to change the contence of the Tooltips of the data points and the date/time information which is shown below the X-axis.
The chart is bound to an IBindingList derived class. The objects in this class hold only two values: a price information and a date/time information.I am able to show the price information in the desired format but I have no idea how I can change the format of the date/time information and I am not able to show the date/time in the Tooltips.
My Tooltips should look like this:
Date:Price
i.e.
2008-07-10:45.05
In my case the right FormatString for the desired data is like this <SERIES_LABEL><DATA_VALUE>. I extended that with the desired formats like that:
<SERIES_LABEL:yyyy-MM-dd>:\n<DATA_VALUE: #,##0.00>
but the Tooltip-contence is shown as below:
2008-07-10 00:00:00:45.05
I don't want the time information to be displayed. Is there a trick to supress the time part or is it a bug in WinChart?
I have even more problems with the date/time data along the X-axis. I don't know where to format it. Can you please give me advise where to define the desired format?
Thanks in advance and best regards,
Gerald
exactly how do you want the text in the tooltip to be aligned?
Thank you very much, Anton!
A fantastic answer and exactly what I was looking for.
Best regards, Gerald
Hi Gerald,
I suppose you wish to achieve a result as at the attached image. I've reached it using custom label and formating X label value (see http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/Chart_Customize_Labels_Using_the_IRenderLabel_Interface.html). In order to have datetime value at the X axis instead of column name I've set UltraChart's property SwapRowsAndColumns to true.The code is below.
public class MyLabel : IRenderLabel { #region IRenderLabel Members public string ToString(System.Collections.Hashtable context) { string value = context["SERIES_LABEL"] as string; if (value != null) { DateTime dateTime; if (DateTime.TryParse(value, out dateTime)) { return dateTime.ToString("yyyy-MM-dd"); } } return string.Empty; } #endregion }
and form load event handler.
private void TestCustomLabelForm_Load(object sender, EventArgs e) { DataTable table = new DataTable("Data"); table.Columns.Add("Price", typeof(double)); table.Columns.Add("Date", typeof(DateTime)); table.Rows.Add(45.50, DateTime.Now.AddDays(1)); table.Rows.Add(145.50, DateTime.Now.AddDays(2)); table.Rows.Add(245.50, DateTime.Now.AddDays(3)); table.Rows.Add(345.50, DateTime.Now.AddDays(4)); ultraChart1.Data.SwapRowsAndColumns = true; ultraChart1.DataSource = table;
// register custom lable for formating tooltip data Hashtable hashtable = new Hashtable(); hashtable.Add("MY_LABEL", new MyLabel()); ultraChart1.LabelHash = hashtable;
// use the custom label ultraChart1.Tooltips.FormatString = "<MY_LABEL>:\n<DATA_VALUE:#,##0.00>";
// format X axis' label ultraChart1.Axis.X.Labels.ItemFormatString = "<ITEM_LABEL:yyyy-MM-dd>"; }