03-16-2010 09:31 AM
Hi All,
I want to mark the points with diffenrent color on a scatterGraph. The color of the point should be produced from the values of a combination of the primary color ( red, green, blue ). Perhabs I have to use the "Color.FromArgb(red, green, blue)" method to change the color. but I have used the "scatterPlot.PointColor = Color.FromArgb(red, green, blue)" to change the color of the whole points on the Plot. The number of the points I have is more than 80 thousand. Do you have any better ideas?
Regard
Michael
Solved! Go to Solution.
03-17-2010 01:10 AM
03-17-2010 03:06 AM
In the exsample you gave, the author want only 2 scatterplot to create 2 typs of color, but I have 80200 points, that should be given thousands of colors.
03-17-2010 05:06 AM
Hi there,
You can customize the way points are drawn in Measurement Studio Graph controls. Check out the Graph Example that comes with Measurement Studio (...\Graph\CustomStyles\...).
You can customize it this way...
1. Write your own CustomStyle deriving the PointStyle class.
2. Override the Draw() method.
3. Override the IsValueDependent property and return true.
Here is the sample code snippet showing the same,
// Use an instance of these style classes for scatterGraph.PlotStyle.
// The point color is dependent on the data.
public class MyCustomStyle1 : PointStyle
{
ScatterPlot scatterPlot;
public MyCustomStyle1(ScatterPlot myPlot)
{
scatterPlot = myPlot;
}
public override void Draw(object context, PointStyleDrawArgs args)
{
Graphics g = args.Graphics;
double x = 0;
double y = 0;
Rectangle rect = new Rectangle((int)args.Graphics.ClipBounds.X, (int)args.Graphics.ClipBounds.Y, (int)args.Graphics.ClipBounds.Width, (int)args.Graphics.ClipBounds.Height);
// You can get the data points x and y by inverse mapping.
scatterPlot.InverseMapDataPoint(rect, new PointF((float)args.X, (float)args.Y), out x, out y);
Color c = Color.White; // Replace the code here to map your data value to a color value.
g.FillRectangle(new SolidBrush(c), new Rectangle(0, 0, 100, 100));
}
public override bool IsValueDependent
{
get { return true; }
}
}
// Point color is not dependent on data
public class MyCustomStyle2 : PointStyle
{
private Random r = new Random();
public override void Draw(object context, PointStyleDrawArgs args)
{
Graphics g = args.Graphics;
Color c = Color.FromArgb(r.Next() % 255, r.Next() % 255, r.Next() % 255);
g.FillRectangle(new SolidBrush(c), new Rectangle(0, 0, 100, 100));
}
public override bool IsValueDependent
{
get { return true; }
}
}
Hope this helps.
03-17-2010 10:12 AM
Hi Vijet
Thank you for your solution. But the "PointStyle" seems to decide all the points on it. We can't let some of them to be red and some of them to be blue at the same time. Let's see the picture blow. What I want to do is to let the color of a point just like the color of the background. If we don't have a efficient way, I have to use 80200 plots to show the Effect. Thanks.
Regards
Michael Sun
03-17-2010 10:45 AM
Hi All
And another question. How can I switch the plots before I append an another point on the ScatterGraph. Thanks.
Regards
Michael Sun
03-17-2010 11:38 PM
Hello Michael,
As I had mentioned, it is possible to customize each data point that you are drawing. In order to do that, you need to write a custom PointStyle. And assign this custom PointStyle to your ScatterPlot.PointStyle. The code snippet in previous reply shows how you to do it.
Write a new custom PointStyle (say MyCustomStyle that derives from PointStyle). PointStyle has an abstract method named Draw(object context, PointStyleDrawArgs args) which you need to override. This is the method that gets called for drawing points. The args parameter provides the graphics object and (args.X, args.Y) that specify the position of the point, with these two you can draw anything you want (like a dot, or a filled rectangle, or a circle). Also, you need to override the IsValueDependent property and return true. If this property is true, then MyCustomStyle.Draw() will be called for each data point. Now, in MyCustomStyle.Draw() all you have to do is to take care of mapping from data to color and draw the point.
If you have tried this and still this solution is not working for you, then I am really missing something. Can you elaborate what your input data is? And what you are expecting as output?. The images that you had posted were looking cool to me... 🙂 But I did not really understand what you were trying to do. What I can think of is that you are drawing only points (and not lines). And have a huge number of points to fill up the area.
You could post some code snippet of what you are trying to do (along with code for the mapping function that converts your data value to a Color). This could be helpful in analyzing the problem that you are facing and to solve it.
03-19-2010 03:22 AM
Hello Vijet,
you are right, thank you for the solution. : D
Michael
12-14-2012 12:38 AM
Is it possible to accomplish the same thing on a WPF chart/plot?