Can I select points in a polar chart in MSChart? - c#

I would like to select points in a Polar chart in MSChart.
I have the ChartAreas.CursorX(and Y).IsUserSelection = true. But when I try to select a zone, the SelectionChanged event does not activate, nor do I see a selection in the chart.

No, looking at the inner code of mschart, the cursors user selection is inhibited when the chart area is circular (as in the polar chart).
In fact the decompiled code of chart.MouseDown is something like this:
if(!area.IsCircular ...)
{
area.CursorX.Cursor_MouseDown(this, e);
area.CursorY.Cursor_MouseDown(this, e);
}
So, the only way is to handle the MouseClick/MouseMove events, get the points values using HitTest method and do whatever you need manually.
For example, this answer explains how to show a tooltip on MouseClick/MouseMove event.
EDIT :
Here's a full working code piece showing how to implement the selection in a polar chart.
Screen-shot:

Related

Interactive chart in C# - set cursor by mouse-click

I'm new to C# and windowsforms applications. I'm trying to create a, at least to some extend, interactive chart. As of now I have not found a library or a built-in method to do what I have in mind.
I want to be able to:
Set a cursor when I click in the chart, set a 2nd cursor when I click again.
When 2 cursors are set, I want to be able to move them with the mouse (click to grab).
(If possible side by side with cursor click-placing:
"Zoom the chart by drawing a rectangle in the chart by clicking and moving the mouse".
My intention is to enable zoom as in: MS Chart Control: prevent zoom when clicking)
I'd like to do this to analyze data (see: Cursor setting example.png). With the cursors it should be possible to easily get the values of the two cursor positions (yellow and red lines) and to measure the distance in between (purple line).
Does anyone of you know how to do this with a mouse_click event OR know a chart library to easily do that?
Thanks for your help!
-Phill
Found another solution to my question and posted it as an answer there: How to retrieve the selected range in the .Net WinForms Chart Control?
To add colored cursors I also add 2 dataseries that are yellow and red to the method private void chart1_SelectionRangeChanging(object sender, CursorEventArgs e):
chart1.Series["CursorX1"].Points.AddXY(x1,y1Min);`
chart1.Series["CursorX1"].Points.AddXY(x1,y1Max);
chart1.Series["CursorX1"].Points.Color = Color.Red;
chart1.Series["CursorX2"].Points.AddXY(x2,y2Min);`
chart1.Series["CursorX2"].Points.AddXY(x2,y2Max);
chart1.Series["CursorX2"].Points.Color = Color.Yellow;

How can i calculate the right coordinates?

I need help. I have a Picturebox and would now like to calculate given coordinates on the picture and then play them in the label. How can I do that best?
As seen in the picture.
If you then click on the image on it, then the data is entered in a list box.
Thank you for your help.
My Picture here: https://prnt.sc/puxyu6
In WPF this particular might for once be the hardest. WPF/UWP is designed for the MVVM, and I do not know anyone but beginners that programm outside of MVVM. And I can not think of way to do this with MVVM.
PictureBox is also the WinForms Element. The WPF equivalent is called Image.
Navigation aids like this are not a trivial thing. One reason there are so few of it. But it comes down to few step process:
Get the x and y pixel coordinates that was clicked, also in relation to that the overall display size of the Image. Usually the MouseClick Event would be the tool for that, but I can not find it. MouseDown or LeftMouseDown are the closest events.
If the entire image was shown with no zooming or cropping, it is now just simple math. If it was 20% of the X axis and 21% of the Y axis, it is pretty easy to figure out where 20% of X and 21 of Y is on the SourceImage.
If there was any zoom or crop, this has to be taken into account, otherwise it is 2.
Equate the Image Pixel position with the coordinates you know for it.
Part 1 would look like this and needs to be registered with the MouseDown or LeftMouseDown Event of the Image:
private void ContentControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//Unpack the sender
Image source = (Image)Sender;
//Get the click point
Point clickPoint = e.GetPosition(source);
//There is more then 1 height Property in WPF.
//The Actuall one is what you are looking for
//Unfortunately you get doubles for this and int for the other. Consider general advise regarding double math
double ElementHeight = source.ActualHeight;
double ElementWidth = source.ActualWidth;
//Do what you need to find the relative position
//Part 2
}
Hopefully someone else can give you a better answer.

How to set series Z-Order in Chart

I have a Chart Control (System.Windows.Form.DataVisualisation.Charting, so WinForms) with multiple series, some are assigned to the primary, and some to the secondary Y-axis.
I need the chart to draw the series in a specific Z-order (meaning which series is drawn first, second, and so on), because some of them are overlapping. I can't find any related property.
I thought the z-order would depend on the order in which the series are added to the SeriesCollection, but this doesn't seem to change anything in my tests.
Am I missing something?
PS: It's not a 3D-Graph. So I am only asking about the order in which the different series are drawn.
The series are drawn in the order they are placed into the Chart.Series collection. Therefore you can automatically send new series to the back by using an Insert instead of an Add:
myChart1.Series.Add(myNewSeries1); // Draws this series on top of the others.
myChart1.Series.Insert(0, myNewSeries2); // Draw this series behind the others.
The following could be converted to an extension method for the chart control and (along with other methods e.g. BringToFront) could then be used in setting the order of series.
public void SendToBack(Series s)
{
if (myChart1.Series.Contains(s))
{
myChart1.Series.Remove(s);
myChart1.Series.Insert(0, s);
}
}
The series are drawn in the order in which they are added to the Chart.Series collection. Add the one you want drawn on top as the last element in the collection.

New textBox and Label obscuring my zedGraph

I have a c# form which is to allow the user to specify a differential equation (dy/dt = -lambda*y) to solve both exactly and approximately (by entering desired values of the intital condition, time step and lambda into textBoxes). Clicking a button calculates the solutions and displays them numerically in boxes as they change over time (using a timer). When the timer finishes, 'Simulation Completed' is displayed in a MessageBox.
At this point, clicking the 'draw graph' button invokes zedGraph to graph the exact and approximate solutions. There are no problems wih calculating and graphing the solutions. The problem is that the label and textBox for timeStep (which I added after adding the zedGraph section) and the 'draw graph' button are superimposed on the graph, partially obscuring it. The textBoxes and labels for lambda and the initial condition were added to the program before the zedGraph part and don't get superimposed.
Is there a way to stop the timeStep label and textBox from being superimposed without having to write the program again, adding the textBox before the zedGraph section?
To summarise: the order in which you add things (at least the way I've done it, if not in general) determines wha happens: adding a textBox before adding the zedGraph section means it doesn't get superimposed on the graph. Add a textBox after adding the zedGraph section and it does get superimposed on the graph. I'm looking for a way o be able to add extra features, having already added the zedGraph section, without them being superimposed on the graph.
You can view 3 screenshots, 2 from before the problem was solved and 1 after here:
https://www.facebook.com/photo.php?fbid=10201376481749572&set=a.10201375193157358.1073741826.1099868090&type=3&theaterset=a.10201375193157358.1073741826.1099868090&type=3&theater
This is a screenshot of the problem:
I just worked out the answer (thanks to God): I just hide the objects I don't want to appear on the graph using the Hide() method at the start of my createGraph() method as follows:
private void CreateGraph(ZedGraphControl zgc)
{
textBox3.Hide();
textBox4.Hide();
label3.Hide();
label5.Hide();
button2.Hide();
Thanks everyone for your input. Quite easy in the end, thankfully... what a relief.
Here's a link to the finished graph:
https://www.facebook.com/photo.php?fbid=10201375420003029&set=a.10201375193157358.1073741826.1099868090&type=3&theater

With Infragistics,how can i mark a Specific point in SplineChart?

Now i have a DataGridView control bingding with some data from DB , and a SplineChart shows the data . i would like to hightlight or mark the Specific point in the Chart when i click the data in the DataGridView control.
what i use to draw the chart is Infragistics ultraChart(SplineChart),C# WinForm.
Can anyone help me with that?
You can use the charts ChartDrawItem method to customize the color of specific data points. There is an example of this in Sung's Chart University blog post in the Changing the Color of an Item Based on a Condition (2D only) section.

Categories