I have made a Chart class. I give our third party software the ability to add series with tooltips. But the tooltips are not working.
The funny thing is, the tooltip works sometimes in the third party software. When I test it in a windows form, it never works...
What am I doing wrong?
Class:
public class DollarChart : System.Windows.Forms.DataVisualization.Charting.Chart
Initialization:
public void Wrapper_Init()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1;
System.Windows.Forms.DataVisualization.Charting.Series MySeries2;
chartArea1 = this.ChartAreas["ChartArea1"];
MySeries2 = this.Series["Series1"];
chartArea1.Name = "Default";
chartArea1.AxisY.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.FixedCount;
chartArea1.AxisY.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.True;
chartArea1.AxisY2.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.FixedCount;
// Invisible series in order to make room for primary Y-axis on chartarea.
MySeries2.Points.Add(0);
MySeries2.Points.Add(490);
MySeries2.Color = System.Drawing.Color.FromName("Transparent");
this.Name = "chart1";
}
Function for inserting data:
public void Wrapper_Populate(System.Single[] AvailDollars, int SeriesSplitter, int PlotHours)
{
System.Double[] Dollars;
Dollars = new System.Double[AvailDollars.Length];
AvailDollars.CopyTo(Dollars,0);
System.Double[] buffer;
buffer = new System.Double[SeriesSplitter];
System.Windows.Forms.DataVisualization.Charting.Series MySeries = new System.Windows.Forms.DataVisualization.Charting.Series();
MySeries.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StackedColumn;
Array.Copy(Dollars, 0, buffer, 0, SeriesSplitter); // Copies from the correct place in the array.
int n = 0;
foreach (double p in buffer)
{
System.Windows.Forms.DataVisualization.Charting.DataPoint Pointer = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
Pointer.YValues[0] = p;
Pointer.ToolTip = "Testing123";
MySeries.Points.Add(Pointer);
if (n == (PlotHours-1)) { break; }
n++;
}
MySeries.Name = "Stacked_Dollars";
MySeries.YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;
this.Series.Add(MySeries);
The reason for setting tooltip per datapoint, is that I will be displaying a calculated total for all series and the value for the specific series in each datapoint. The reason for doing array.copy is that I receive the values neatly packed in a 600 element array, divided into sections for each series, in addition, I need to convert from System.Single to System.Double.
I'm sure you will be asking why I'm doing this. Were using third party software that uses something called quickscript.net. One of the things this third party software lacks, is charting. We are, however, able to import custom controls. So we have to work around the limitations by making what they call "Client controls" and "Script function library".
I have tried different small tweaks, but none of them seem to work. What seems to work, is doing the hittest workaround, even though I don't like it very much. The problem with this is that the keywords you are able to use like "#VAL" and "\n" does not work when you are copying the tooltip. So you actually have to translate them in the eventhandler.
This is a solution to the problem, but not the solution. So I won't accept it unless no other answers appear in the next month..
this.GetToolTipText += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs>(this.Chart1_GetToolTipText);
private void Chart1_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e)
{
// Check selected chart element and set tooltip text
if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint)
{
int i = e.HitTestResult.PointIndex;
DataPoint dp = e.HitTestResult.Series.Points[i];
decimal YValue = System.Convert.ToDecimal(dp.YValues[0]);
YValue = System.Math.Round(YValue, 2);
e.Text = dp.ToolTip.Replace("\\n","\n").Replace("#VAL",YValue.ToString());
}
}