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;
I am creating a web application using c#. I have four values(or series) volt,current,wh and temperature which I will have to plot in a chart control against time which(time) will be shown in x-axis. All things done correctly. But the range of the values are different like one is in range of more than 1000,another lies between 0 to 10,another shows negetive value,etc. I want to create different y-axis for each series.I had created two y-axis which is a property of series(YAxisType),primary and secondary. Is it possible to create multiple y-axis?I had searched in google but didn't get any proper answer. Please help me.
You can only use 2 y-axis(primary and secondary)
But you can create a few chart areas within one chart control
Or you can add a button that will hide one chart control and show another(with others 2 axis)
How does one set the alignment of text within a chart legend object? I've tried using:
myChartName.Legends["mySeriesName"].Alignment = stringAlignment.Near
With no effect. I've also tried to create custom legend items, again resulting in no effect. Text is ALWAYS centered (along with the series marker) in the legend "box". The only text I have been able to align is the title, but I don't need titles in my application.
My research to date says the legend object is basically a table with (by default) two cells. If that is the case there should be a way to access those cells and manipulate them as table cells. So, what gives? Why can't I access the text alignment properties of the legend object? Clearly, there is something I'm missing, but for the life of me I can't seem to figure this out. Quite frustrating.
Problem solved. The CustomItem approach wasn't working either, so I tried using the LegendCellColumn Class.
I changed the LegendStyle from Column to Row, then added two CellColumns, one for the series symbol and one for the legend text. Set the alignment, margins, and column widths (that turned out to be the trick), and voila; a legend that looks like I want. Here's the code for anyone with a similar issue.
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.SeriesSymbol, ""));
chartSel.Legends[ySeries.Name].CellColumns[0].Alignment = ContentAlignment.TopLeft;
chartSel.Legends[ySeries.Name].CellColumns[0].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[0].MinimumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns[0].MaximumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.Text, ySeries.Name));
chartSel.Legends[ySeries.Name].CellColumns[1].Alignment = ContentAlignment.MiddleLeft;
chartSel.Legends[ySeries.Name].CellColumns[1].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[1].MinimumWidth = 1500;
chartSel.Legends[ySeries.Name].CellColumns[1].MaximumWidth = 1500;
It's probably not the most efficient way to do it, but it works. Technically, the legend symbol and text are still centered in the object, but because I'm forcing the widths of the two columns it has the appearance of being left-justified.
Hopefully, this may help another newbie like me avoid days of consternation.
My understanding is that Legend alignment relates to the Docking property, not really how the text is aligned within the legend. So setting Alignment to Near means positioning the legend box near the Docking direction.
It is quite hard to explain this textually. The MS Chart Samples have a subsection named Chart features -> Legends -> Style and Auto Positioning which will help you play with those two properties and understand how they are meant to work.
For inner legend alignment, you may need to use Legend.CustomItems and define LegendCell individually.
chart.Legends["Default"].CustomItems.Clear();
chart.Legends["Default"].CustomItems.Add(new LegendItem("LegendItem", Color.Red, ""));
chart.Legends["Default"].CustomItems[0].Cells.Add(new LegendCell(LegendCellType.Text, "My text", ContentAlignment.MiddleLeft));
This is described inside the Chart features -> Legends -> Legend Cells section of the samples.
While continuing to try to figure this out I stumbled on this tidbit of info from the following MSDN library page:
http://msdn.microsoft.com/en-us/library/dd456711(v=vs.100).aspx
"NOTE: You cannot adjust the individual legend items and cells in the Chart.Legends collection. To adjust them, use custom legend items."
So, back to the CustomItem route. I've got this code gleaned from several sources (including you, Dominique, thanks):
chartSel.Legends.Add(ySeries.Name);
chartSel.Series[ySeries.Name].IsVisibleInLegend = false;
chartSel.Legends[ySeries.Name].CustomItems.Clear();
LegendItem li = new LegendItem();
li.ImageStyle = LegendImageStyle.Line;
li.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.TopLeft);
li.Cells[0].BackColor = Color.CornflowerBlue; //color is only to see the cell bounds
li.Cells.Add(LegendCellType.Text, ySeries.Name, ContentAlignment.TopLeft);
li.Cells[1].BackColor = Color.Aquamarine; //color is only to see the cell bounds
chartSel.Legends[ySeries.Name].CustomItems.Add(li);
From what I can find it should work, but it doesn't. It results in a legend object with two cells; the first is empty and the second has left-justified text. I tried to post an image of it, but the system says I'm not yet worthy.
Why there is no line for the series symbol is also a mystery, but that's another problem to solve. The text justification issue is my main concern at the moment. It looks like the text within the cells is left-justified as desired, but the cells themselves are centered in the legend object; not what I wanted. I want those cells to be left-justified in the object too, so the first cell is against the left edge of the legend object.
Ideas?
Anybody can guide me why MS Column Chart is showing arrows. When I am displaying label values then start displaying it.
Please the below snap:
MSChart uses SmartLabel Technology to display labels.
There are two ways you can get rid of your lines.
Disable the SmartLabel Technology
series.SmartLabelStyle.Enabled = False;
But you may not like the end result as the labels might collide and your chart will become unreadable
Or you can selectively do this
s.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.None;
s.SmartLabelStyle.CalloutLineAnchorCapStyle = LineAnchorCapStyle.None;
s.SmartLabelStyle.CalloutLineColor = Color.Transparent;
But again it might confuse end user and the label might not be near the correct datapoint/bar
More Information here
http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.smartlabelstyle.aspx
http://support2.dundas.com/OnlineDocumentation/WebChart2005/UsingSmartLabels.html
This line is enough for removing arrow sign in chart.
series.SmartLabelStyle.CalloutLineColor = Color.Transparent;
Check the below code its worked for me
chart1.Series[0].SmartLabelStyle.CalloutLineAnchorCapStyle = LineAnchorCapStyle.None;
Is it possible to force the display of grid lines on the chart with the dates for the extreme data points?
I've tried almost every configuration of following Chart DateTimeAxis properties: IntervalType, Interval, Minimum and Maximum but I wasn't satisfied with the result.
Setting properties Minimum and Maximum didn't solve the problem.
For instance (IntervalType="Days" , Interval="4" , Minimum="1/1/2010" , Maximum="1/31/2010"):
If I'm lucky I will generate some random data where only one extreme point will have the date with grid line.
Does somebody have an idea how to solve the problem mentioned above?
Edited to add
I added a bounty to this question since I really need a fast solution for this issue.
I am binding a series of specific pairs to my chart and I'd like to display excactly those given DateTime values on the x-axis.
Since these are usually dates like 6/30/11, 6/30/12 and so on, I can't use the Interval/IntervalType properties because adding 1 year or 365 days to 6/30/11 doesn't necessarily result in 6/30/12.
So what I need to do is either disable the "automatic axis label generation" of the DateTime axis or use another axis type.
LinearAxis doesn't work because it expects double values and CategoryAxis is not an option because it displays the axis labels between two tickmarks instead of underneath them.
I am very grateful for any help!
To be perfectly clear, here is what axis labels I need (taken from another chart component):
This is what I get so far with the Silverlight 4 Toolkit:
€: I also opened a thread in the official Silverlight Toolkit Support Forums.
The vertical lines are set where you specify an interval.
There is no vertical line for the data for 1/31/2010 as it does not fall on an interval.