Hi,
I am using the scichart for WPF an came across a problem. I am trying to create a thumbnail image of a size 300×200 pixels of my chart. I have tried using the ExportToStream method with option of specifying the size output, but that creates a smaller resolution image of my chart. I was hoping that it will resize the chart to the desired size and then make an image.
So I tried a second option which was to put the chart in a user control of a certain size and then use the RenderTargetBitmap to render the user control in an image. That resulted in a partial chart without the chart lines. Take a look at the attached?
Any ideas how to make the chart to be rendered in memory in full for a certain size?
Kind regards,
Boštjan
- Boštjan Arzenšek asked 1 year ago
- You must login to post comments
I am considering applying server-side licensing for my javerScript application.
In the document below, there is a phrase “Our server-side licensing component is written in C++.”
(https://support.scichart.com/index.php?/Knowledgebase/Article/View/17256/42/)
However, there is only asp.net sample code on the provided github.
(https://github.com/ABTSoftware/SciChart.JS.Examples/tree/master/Sandbox/demo-dotnet-server-licensing)
I wonder if there is a sample code implemented in C++ for server-side licensing.
Can you provide c++ sample code?
Also, are there any examples to run on Ubuntu?
- Boštjan Arzenšek answered 1 year ago
- last edited 1 year ago
- That’s strange, I tested it too, and the gridlines were being exported. Another aspect of our ‘export with size’ is a full clone is done of the chart. Do you have custom styles applied to gridlines? If so — that might have gotten lost during the clone + export
- You are correct, we use a custom style for the gridlines. I just tested and it is working now as expected. Thanks again for your help.
- Hi Andrew, One question. Is it possible to export the graph that is created “on the fly” in code behind and was never rendered on the UI thread? So completely created in memory without a UI control. Thanks in advance! Kind regards, Boštjan
- You must login to post comments
SciChartSurface.ExportToBitmapSource() has an overload to accept the size property. This will create a clone/copy of the chart in memory at a specific size off screen, then render that chart to bitmap.
If you’re scaling the chart down to 300×200 during this process you should get a smaller image.
Try our WPF Export Screenshot Options example as a starting point. You can find the code for this here.
Modify the code in ExportAndScreenshotOptionsChart.xaml.cs to do this:
private void ExportPngInMemory(object sender, RoutedEventArgs e)
{
string filePath;
if(GetAndCheckPath("PNG | *.png", out filePath))
{
sciChart.ExportToFile(filePath, ExportType.Png, false, new Size(300, 200));
}
}
Now run the example and click on the Export PNGb button
I get a thumbnail outputted when doing this. Of course, its scaled down (as expected) so fonts, line series etc are smaller. If you want to have large fonts and thicker lines when scaling a chart down into a thumbnail this becomes a more difficult challenge
Best regards
Andrew
- Andrew Burnett-Thompson answered 1 year ago
- You must login to post comments
Hi Andrew,
Thank you for your answer. What I am trying to achieve you referred as a “more difficult challenge”. I am trying to create a thumbnail image of a chart that has the same line sizes, fonts,.. See the attached “original chart”, desired “thumbnail” and the result of rendering the thumbnail in memory, which loads the axes title, but doesn’t render the series. It looks like to me, that the series needs to have a control that is on the UI thread in order to render it. Is there any chance to render the series without having an actual element on the UI thread?
In the attached you will also see that I was able to create a thumbnail by adding a control in a window, showing and immediately closing it just so that the series was rendered, but that is something, that I wouldn’t want to do.
Grid grid = new Grid();
var multiLinePreviewChart = new MultiLineTest();
multiLinePreviewChart.DataContext = viewmodel;
grid.Children.Add(multiLinePreviewChart);
grid.Width = 300;
grid.Height = 200;
grid.Measure(new Size(150,100));
grid.Arrange(new Rect(0, 0, 300, 200));
grid.UpdateLayout();
Window w1 = new Window()
{
Width = 0,
Height = 0,
WindowStyle = WindowStyle.None,
ShowInTaskbar = false,
ShowActivated = false,
Content = grid
};
w1.Show();
// Export Action is binded behavior that calls the ExportToFile method on the chart
viewmodel.ExportAction?.Invoke(filepath, eventArgs.ExportType);
w1.Close();
So, is there an option to render and smaller chart in memory with the same components size(lines, fonts,..)?
- Boštjan Arzenšek answered 1 year ago
- last edited 1 year ago
- You must login to post comments
Hi Bostjan, I was thinking about this at the weekend.
The fact fonts, stroke thicknesses are scaled when exporting an image with size is by-design, which means it should be possible to disable this scaling.
Try overriding the function GetScaleFactorXy on SciChartSurface and returning 1. Then re-doing your export.
e.g.
class SciChartSurfaceEx : SciChartSurface
{
protected override double GetScaleFactorXy(Size size) { return 1; }
}
private void ExportPngInMemory(object sender, RoutedEventArgs e)
{
string filePath;
if(GetAndCheckPath("PNG | *.png", out filePath))
{
// Assuming this is an instance of SciChartSurfaceEx
sciChart.ExportToFile(filePath, ExportType.Png, false, new Size(300, 200));
}
}
We haven’t tested this, but this is just a suggestion for now. We will look into other solutions if you still need help.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 1 year ago
- You must login to post comments
Please login first to submit.