سؤال

I have a mschart (System.Windows.Forms.DataVisualization.Charting.Chart) control added to a windows form that I have configured to be a point chart (not fast point). I already know how to individualize the marker size of each point in a series via:

MyChart.Series[0].Points[0].MarkerSize = K;

But I have been unable to find out what this value is actually based on as it doesn't seem to be linear. What I would like to do, is to have some way of computing an effective marker size that would be a radius or diameter in relation to the x or y axis.

In other words, supposing I have a scatter chart whose x and y axis values go from -100 to 100 (say, in "meters") each and I want to add a circular point that will take up a radius of 5 meters on that scale, how would I go about doing this? For example that same point would appear visually smaller if I changed the scale to be -200 to 200. I have searched everywhere and could not find a definite answer.

Thanks in advance!

هل كانت مفيدة؟

المحلول

The marker size is in pixels. You can try this code (untested!):

static int CalcualteMarkerPixelSize(double diameterOnXAxis, Chart chart)
{
    double innerWidthScale = chart.ChartAreas[0].AxisX.Maximum - chart.ChartAreas[0].AxisX.Minimum;
    float innerWidthPct = chart.ChartAreas[0].InnerPlotPosition.Width / 100;
    float innerWidthPixels = chart.Width*innerWidthPct;
    return (int) (diameterOnXAxis/innerWidthScale*innerWidthPixels);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top