Profile Picture

Standardizing chart size

Posted By rich dudley 6 Years Ago
Author
Message
rich dudley
Question Posted 6 Years Ago
View Quick Profile
Forum Guru

Forum Guru (51 reputation)Forum Guru (51 reputation)Forum Guru (51 reputation)Forum Guru (51 reputation)Forum Guru (51 reputation)Forum Guru (51 reputation)Forum Guru (51 reputation)Forum Guru (51 reputation)Forum Guru (51 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 33, Visits: 76
when setting the size of the chart or the chartControl I dont seem to get a predictable output size of the file exported fromt the chartControl. For example:
int Length = 516;
int Height = 288;
NCartesianChart chart = (NCartesianChart)chartControl.Charts[0];
chart.Size = new NSizeL(new NLength(Length, NGraphicsUnit.Point), new NLength(Height, NGraphicsUnit.Point));
The size of the chart output by this is 482.023 pt x 388.919 pt.  If I add the following:
chart.BoundsMode = BoundsMode.Stretch;
The size of the chart becomes 682.023 pt x 388.919 pt.  How do I get a predictable size output? I currently have export it repeatedly, gradually adjusting the size until it is the size I want.
     



Nevron Support
This post has been flagged as an answer
Posted 6 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746

Hi Rich,

The BoundsMode property specifies how the chart fits inside the bounds determined by the layout - in case of Fit the chart maintains aspect ratio and in case of Stretch it stretches to fill the available size without maintiaining aspect. The following code shows how to export a chart control where the chart occupies 400x300 pixels at 96 dpi:


   using (NChartControl chartControl = new NChartControl())
   {
    NChart chart = chartControl.Charts[0];
    chart.DockMode = PanelDockMode.Fill;
    chart.BoundsMode = BoundsMode.Stretch;

    NBarSeries bar = new NBarSeries();

    bar.Values.Add(10);
    bar.Values.Add(20);
    bar.Values.Add(20);

    chart.Series.Add(bar);

    chartControl.ImageExporter.SaveToFile("c:\\temp\\chartImage.png", new NSize(400, 300), new NResolution(96, 96), new NPngImageFormat());
   }
You can also take a look at the examples shipped with the control showing how BoundsMode works:
All Examples \ Layout \ Bounds Mode - Fit
All Examples \ Layout \ Bounds Mode - Stretch

Hope this helps - let us know if you meet any problems.



Best Regards,
Nevron Support Team



Nevron Support
This post has been flagged as an answer
Posted 6 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746

Hi Rich,
How do you specify the chart size relative to the size of the control? In the reference code we posted the chart uses docking so it occupies all the avaiable space. In your case you may need to adjust the Location / Size properties of the chart panel to match the 0, 0 and rightmost, bottom coordinates of the chart if you don't use docking:


chart.Location = new NPointL(0, 0);
chart.Size = new NSizeL(new NLength(100, NRelativeUnit.ParentPercentage), new NLength(100, NRelativeUnit.ParentPercentage)));



Best Regards,
Nevron Support Team



Nevron Support
This post has been flagged as an answer
Posted 6 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746

Hi Rich,
Yes currently the chart does not measure how much labels fall outside the axis range, but we plan to introduce this feature in the upcoming release of the control. For the time being you can apply some margins from the top side of the control - for example:

NChart chart = nChartControl1.Charts[0];
chart.Margins = new NMarginsL(0, 10, 0, 0);



Best Regards,
Nevron Support Team



Nevron Support
This post has been flagged as an answer
Posted 6 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746
Hi Rich,
The target resolution controls the dpi of the target device and how sizes specified in points, inches etc. are converted to pixels. This matters when you print or display the chart on high res display (4K for example), because you want the font size to remain constant relative to the viewer but actually increase in terms of rasterized pixels. In the case of SVG you can simply specify 96 and adjust the labels, margins etc. based on that resolution as the SVG is scalable and the target resolution there does not matter except for the unit conversions.


Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic