Hi Kevin,
Probably the best way to do it is to use a points series with markers and hide the points.
Regarding your questions:
1) I tried using chart panel Width / Height, but the numbers were very small and I do not know how to convert them to pixels. Instead, I used the size of the chart control. Am I converting the chart control size to pixels correctly? This is not the same as the chart panel size, but, even with no legend, there is still a size discontinuity.
You need to access the chart panel Bounds (Width / Height are used to specify an aspect of the chart).
2) When I use ParentPercentage in setting the MarkerSize of a series, what exactly is the Parent?
It is generally the a size relative to the parent panel bounds Width or Height, but with some exceptions:
1. When the length is used for X coordinates - it is percentage of the Width.
2. When the length is used for Y coordinates - it is percentage of the Height.
3. When the length is used for both X and Y coordinates - it is calculated as (Width + Height) * Percentage / 200.0;
3) Ideally I would read the size of the marker directly in pixels - can I do this?
No, however the code below shows how to calculate this correctly.
We tested with the following code:
using System;
using System.Windows.Forms;
using Nevron.Chart;
using Nevron.Chart.WinForm;
using Nevron.GraphicsCore;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
NChart chart = nChartControl1.Charts[0];
chart.BoundsMode = BoundsMode.Fit;
NPointSeries point = new NPointSeries();
point.UseXValues = true;
point.DataLabelStyle.Visible = false;
point.MarkerStyle.Visible = false;
Random rand = new Random();
for (int i = 0; i < 10; i++)
{
double yValue = rand.Next(100);
double xValue = rand.Next(100);
point.XValues.Add(xValue);
point.Values.Add(yValue);
}
chart.Series.Add(point);
chart.PaintCallback = new NPaintCallback(nChartControl1);
}
internal class NPaintCallback : INPaintCallback
{
public NPaintCallback(NChartControl chartControl)
{
m_ChartControl = chartControl;
}
NChartControl m_ChartControl;
float DefaultPercentagePointSize = 10;
float MaximumPointSize = 10;
#region INPaintCallback Members
public void OnAfterPaint(NPanel panel, NPanelPaintEventArgs eventArgs)
{
}
public void OnBeforePaint(NPanel panel, NPanelPaintEventArgs eventArgs)
{
NChart chart = (NChart)panel;
bool seriesFound = false;
bool requiresRecalculate = false;
NLength requiredMarkerSize = NLength.Empty;
foreach (NSeries series in chart.Series)
{
NPointSeries pointSeries = series as NPointSeries;
NLineSeries lineSeries = series as NLineSeries;
if (pointSeries != null || lineSeries != null)
{
// Determine if size needs changing for the first series only.
if (!seriesFound)
{
// Set flag so this calculation is only executed once
seriesFound = true;
// Determine if the point size should be changed
bool overMaximum = ((chart.Bounds.Width + chart.Bounds.Height) * this.DefaultPercentagePointSize / 200.0) > (double)this.MaximumPointSize;
NLength markerSize = pointSeries != null ? pointSeries.Size : lineSeries.MarkerStyle.Width;
requiresRecalculate = overMaximum ? markerSize.MeasurementUnit == NRelativeUnit.ParentPercentage : markerSize.MeasurementUnit == NGraphicsUnit.Pixel;
requiredMarkerSize = overMaximum ? new NLength((float)this.MaximumPointSize, NGraphicsUnit.Pixel) : new NLength((float)this.DefaultPercentagePointSize, NRelativeUnit.ParentPercentage);
}
// Reset the point size if required
if (requiresRecalculate)
{
if (pointSeries != null)
pointSeries.Size = requiredMarkerSize;
else
{
lineSeries.MarkerStyle.Width = requiredMarkerSize;
lineSeries.MarkerStyle.Height = requiredMarkerSize;
}
}
}
}
// Recalculate the layout only if necessary
if (requiresRecalculate)
{
this.m_ChartControl.Document.Calculate();
this.m_ChartControl.RecalcLayout();
}
}
#endregion
}
private void button1_Click(object sender, EventArgs e)
{
nChartControl1.ShowEditor();
}
}
}
Let us know if you meet any problems.
Best Regards,
Nevron Support Team