NHeatMapSeries combined with NLineSeries


https://www.nevron.com/Forum/Topic12367.aspx
Print Topic | Close Window

By joern kunze - 6 Years Ago
Hello Experts,

I have a NHeatMapSeries which looks like:
https://www.nevron.com/forum/uploads/images/13e3edb2-0b81-4adf-bf7b-ed89.jpg
So far so good. But now I want to add a line with a anchored CallOut-Label at y=5:

   NLineSeries line = (NLineSeries)_oChart.Series.Add(SeriesType.Line);
    line.Name = "ReferenceLine";
    line.UseXValues = true;
    line.MarkerStyle.Visible = false;
    line.DataLabelStyle.Visible = false;
    line.InflateMargins = false;
    line.BorderStyle.Color = oLine.Color;
    line.BorderStyle.Width = new NLength(oLine.Thickness, NPointGraphicsUnit.Point);
    line.Values.AddRange(oLine.YValues);
line.XValues.AddRange(oLine.XValues);
     // Create a rounded rect callout 
      NRectangularCallout m_RectangularCallout = new NRectangularCallout();
      int iLabelPos = 8; 
     ...
     // Anchor the callout to data point #0 of the line series
      NDataPointAnchor anchor = new NDataPointAnchor(line, 1, ContentAlignment.MiddleCenter, StringAlignment.Center);
      m_RectangularCallout.Anchor = anchor;
      m_RectangularCallout.AlwaysInsideParent = true; 
_NevronChart.Panels.Add(m_RectangularCallout);

Result: The Callout label is plotted (see picture lower right: label with green back colour)- but no line is plotted. The very same approach does work for Point- and Line plots though. What must be done to make it working with NHeatMapSeries ?

Thanks for the help,
best regards,
Joern


By Nevron Support - 6 Years Ago
Hi Joern,

Most likely the line series is beneath the heatmap - we tested with the following code and it was working properly:

  private void Form1_Load(object sender, EventArgs e)
  {
   // set a chart title
   NLabel title = new NLabel("Wafer Chart");
   title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 18, FontStyle.Italic);
   title.TextStyle.FillStyle = new NColorFillStyle(Color.Blue);

   // configure chart
   NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];

   NHeatMapSeries heatMap = new NHeatMapSeries();
   chart.Series.Add(heatMap);

   NHeatMapData data = heatMap.Data;

   heatMap.Palette.Mode = PaletteMode.AutoFixedEntryCount;
   heatMap.Palette.AutoPaletteColors = new NArgbColorValue[] { new NArgbColorValue(Color.Green), new NArgbColorValue(Color.Red) };
   heatMap.Palette.SmoothPalette = true;

   int gridSizeX = 100;
   int gridSizeY = 100;
   data.SetGridSize(gridSizeX, gridSizeY);

   int centerX = gridSizeX / 2;
   int centerY = gridSizeY / 2;

   int radius = gridSizeX / 2;
   Random rand = new Random();

   for (int y = 0; y < gridSizeY; y++)
   {
    for (int x = 0; x < gridSizeX; x++)
    {
     int dx = x - centerX;
     int dy = y - centerY;

     double pointDistance = Math.Sqrt(dx * dx + dy * dy);

     if (pointDistance < radius)
     {
      // assign value
      data.SetValue(x, y, pointDistance + rand.Next(20));
     }
     else
     {
      data.SetValue(x, y, double.NaN);
     }
    }
   }

   NLineSeries line = new NLineSeries();
   chart.Series.Insert(0, line);
   line.Name = "ReferenceLine";
   line.UseXValues = true;
   line.MarkerStyle.Visible = false;
   line.DataLabelStyle.Visible = false;
   line.InflateMargins = false;
   line.BorderStyle.Color = Color.Cyan;
   line.BorderStyle.Width = new NLength(2, NPointGraphicsUnit.Point);

   for (int i = 0; i < 100; i++)
   {
    line.Values.AddRange(i);
    line.XValues.AddRange(i);
   }

   // Create a rounded rect callout
   NRectangularCallout rectangularCallout = new NRectangularCallout();
   rectangularCallout.Text = "Test";
   rectangularCallout.UseAutomaticSize = true;

   // Anchor the callout to data point #0 of the line series
   NDataPointAnchor anchor = new NDataPointAnchor(line, 1, ContentAlignment.MiddleCenter, StringAlignment.Center);
   rectangularCallout.Anchor = anchor;
   rectangularCallout.AlwaysInsideParent = true;
   chart.ChildPanels.Add(rectangularCallout);
  }

Note that the code changed to insert the line series at the first place in the collection:
  NLineSeries line = new NLineSeries();
   chart.Series.Insert(0, line);
instead of adding it at the back.
Hope this helps - let us know if you meet any problems or have any questions.


By joern kunze - 6 Years Ago
... thanks a lot for the explenation - now I got it working. 

By the way, to avoid changing the series index (which might cause some trouble in existing code), I just inverted the plot order:

oChart.Axis(StandardAxis.Depth).ScaleConfigurator.Invert = true;

Best regards,
Joern