INPaintCallBack.OnBeforePaint interfering with NChartControl.ImageExporter


Author
Message
Kevin Harrison 1
Kevin Harrison 1
Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)
Group: Forum Members
Posts: 176, Visits: 1.9K
This is a behaviour change between 16.8.8.12 and 17.3.6.12

On your helpful recommendation we added an INPaintCallBack and use OnBeforePaint to allow the user to change the symbol sizes on chart lines by turning the mouse wheel. This works fine in 16.8.8.12 and 17.3.6.12. However, we have found that the OnBeforePaint code affects chart export in 17.3.612 - the chart is not resized in the export when the export size is changed form the default size.

I have tracked this to these lines of code:

this.chartControl.document.Calculate();
this.chartControl.RecalcLayout();

If they are removed the export is the correct size but the symbol resizing has not been applied to the export.

Is there a different way to achieve this in 17.3.6.12?

I also notice that previously I could reorganise panel layout; e.g. moving the legend panel from right to left and the chart would redraw. Now I have to explicitly call NChartControl.Refresh().

Some general advice on the changes and recommended strategies would be much appreciated.

Thanks

Kevin
Replies
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Kevin,

We were not able to replicate the problem - we tested with the following code:

using Nevron.Chart;
using Nevron.Chart.WinForm;
using Nevron.GraphicsCore;
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
 public partial class Form1 : Form
 {
  public Form1()
  {
   InitializeComponent();
  }

  class MyPaintCallback : INPaintCallback
  {
   public MyPaintCallback(NChartControl chartControl)
   {
    m_ChartControl = chartControl;
   }
   public void OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs)
   {
    throw new NotImplementedException();
   }

   public void OnBeforePaint(NPanel panel, NPanelPaintEventArgs eventArgs)
   {
    bool requiresRecalculate = true;

    foreach (NSeries series in m_ChartControl.Charts[0].Series)
    {
     NPointSeries pointSeries = series as NPointSeries;
     if (pointSeries != null)
     {
      pointSeries.Size = new NLength(4, NGraphicsUnit.Pixel);
     }
    }

    if (requiresRecalculate)
    {
     m_ChartControl.document.Calculate();
     m_ChartControl.RecalcLayout();
    }
   }

   NChartControl m_ChartControl;
  }


  private void Form1_Load(object sender, EventArgs e)
  {
   NChart chart = nChartControl1.Charts[0];
   chart.DockMode = PanelDockMode.Fill;

   NPointSeries point = new NPointSeries();
   chart.Series.Add(point);
   Random rand = new Random();

   for (int i = 0; i < 20; i++)
   {
    point.Values.Add(rand.Next(100));
   }

   chart.PaintCallback = new MyPaintCallback(nChartControl1);

   nChartControl1.ImageExporter.SaveToFile("c:\\temp\\check.bmp", new NBitmapImageFormat());
  }
 }
}

And both the chart on the form and the exported image looked correct.



Best Regards,
Nevron Support Team


Kevin Harrison 1
Kevin Harrison 1
Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)
Group: Forum Members
Posts: 176, Visits: 1.9K
"the chart is not resized in the export when the export size is changed from the default size."

You are using the default size.
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
Hi Kevin,
The control works properly - when you call nChartControl.RecalcLayout it will use the default view context which has different size than the one in the view context that currently serves for image export - that's why you get the same size in the
chart rendered to bitmap as the one on the screen. The solution is to pass the view context of the current paint:

   public void OnBeforePaint(NPanel panel, NPanelPaintEventArgs eventArgs)
   {
    bool requiresRecalculate = true;

    foreach (NSeries series in m_ChartControl.Charts[0].Series)
    {
     NPointSeries pointSeries = series as NPointSeries;
     if (pointSeries != null)
     {
      pointSeries.Size = new NLength(4, NGraphicsUnit.Pixel);
     }
    }

    if (requiresRecalculate)
    {
     m_ChartControl.document.Calculate();
     m_ChartControl.document.RecalcLayout(eventArgs.Context);
    }
   }

We tested this approach and it was working OK. Let us know if you meet any problems.




Best Regards,
Nevron Support Team


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Kevin Harrison 1 - 8 Years Ago
Nevron Support - 8 Years Ago
Kevin Harrison 1 - 8 Years Ago
Nevron Support - 8 Years Ago
Kevin Harrison 1 - 8 Years Ago
                         Hi Kevin, The control works properly - when you call...
Nevron Support - 8 Years Ago
Kevin Harrison 1 - 8 Years Ago
Nevron Support - 8 Years Ago
Kevin Harrison 1 - 8 Years Ago
Nevron Support - 8 Years Ago
                         Bugfinder strikes again! :-) Thanks for the speedy response. Is the...
Kevin Harrison 1 - 8 Years Ago
                             Hi Kevin, Yes that's the latest one - do you meet any problems?
Nevron Support - 8 Years Ago
                                 Hi guys Sadly I have found a problem with using...
Kevin Harrison 1 - 7 Years Ago
                                     Hi Kevin, It's most likely something related to the selection, but its...
Nevron Support - 7 Years Ago
                                         I've found what's happening and have a fix, though I'd like advice on...
Kevin Harrison 1 - 7 Years Ago
                                             Hi Kevin, It is normal to have a render pass on the chart when it...
Nevron Support - 7 Years Ago
Kevin Harrison 1 - 7 Years Ago
Nevron Support - 7 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search