Can I draw vertical lines on the LineSeries Graph? - c#

I'm making an application with some OxyPlot Graphs.
I want to make a graph that has a vertical line on the LineSeries Graph like this link:
http://theclosetentrepreneur.com/how-to-add-a-vertical-line-to-an-excel-xy-chart
(My ideal image is in "Tips on formatting your chart…".)
How can I make this graph?

You can make use of LineAnnotation for the purpose. For example,
var annotation = new LineAnnotation();
annotation.Color = OxyColors.Blue;
annotation.MinimumY = 10;
annotation.MaximumY = 40;
annotation.X = 5;
annotation.LineStyle = LineStyle.Solid;
annotation.Type = LineAnnotationType.Vertical;
MyPlotModel.Annotations.Add(annotation);
Sample Output

Related

Winform Chart control - to keep displaying same bar width for different data

I'm familiar with C# and Winform, but new to Chart control. I'm using VS2013 built in System.Windows.Forms.DataVisualization.Charting.Chart to display bar for two points. Here's simply the code:
private void Form1_Load(object sender, EventArgs e)
{
Chart c = new Chart();
c.Dock = DockStyle.Fill;
ChartArea a = new ChartArea();
a.AxisX.Minimum = 0;
a.AxisX.Maximum = 4;
a.AxisY.Minimum = 0;
a.AxisY.Maximum = 2;
c.ChartAreas.Add(a);
Series s = new Series();
//*******************
s.Points.AddXY(1, 1);
//s.Points.AddXY(2, 2);
s.Points.AddXY(3, 2);
//*******************
c.Series.Add(s);
this.Controls.Add(c);
}
Please note the commented part, the points (2,2) and (3,2) are only different data, and have nothing to do with display style(I guess?). So this behavior seems very strange and so far I haven't found any solution to keep displaying (3,2) like (2,2).
You need to add the below codes in order to achieve the desired output:
1] Fix the interval for the Axis so the axis label and Grid lines do not change.
a.AxisX.Interval = 1;
2] Fix the bar width for the series. You can use PixelPointWidth to specify the width in Pixels or PointWidth in Points.
Example using PixelPointWidth:
s["PixelPointWidth"] = "20";
Also, since you are using c.Dock = DockStyle.Fill; to fill the chart into whole form, fixed width will not be good if you scale the form.
You can use MinPixelPointWidth and MaxPixelPointWidth to give the range to the width.
s["MinPixelPointWidth"] = "20";
s["MaxPixelPointWidth"] = "80";
Check this link for details on different chart elements.
Technical Reference for detailed documentation on Chart controls. This may be long but important to understand the details.

Chart set Vertical Bar Marker

On my Chart, I want to put an obvious red vertical bar which goes from a specific point on the plot down to the x-axis. Is there a way to do this? Based on the documentation, it doesn't seem like this option is available or perhaps I'm looking in the wrong area.
The most obvious way is to add a VerticalLineAnnotation.
Here is an example:
First I set up a few things:
int yourPointIndex = 635;
Series S1 = chart1.Series[0];
ChartArea CA1 = chart1.ChartAreas[0];
Now I create the Annotation and style it a little:
VerticalLineAnnotation LA = new VerticalLineAnnotation();
LA.LineColor = Color.Red;
LA.LineWidth = 9;
LA.IsInfinitive = false;
LA.AnchorDataPoint = S1.Points[yourPointIndex]; ;
Now I position it with the Point in question:
LA.X = S1.Points[yourPointIndex].XValue;
LA.Y = S1.Points[yourPointIndex].YValues[0];
// this makes the bar go down to the zero axis
LA.Height = LA.Y;
// this makes it go down all the way to the x-axis:
LA.Height = LA.Y - CA1.AxisY.Minimum;
// we should clip it to our chartarea:
LA.ClipToChartArea = CA1.Name;
Finally it is added to the Annotations collection of the Chart.
chart1.Annotations.Add(LA);
Note that Annotations can be adorned and made to be moveable..
Note: The code above was written for and tested with Winforms but the MS Chart control is rather similar in all its versions..

How to set Spline chart 3d in .NET

I am using the chart component of .NET Framework 4.5 in C#.
When I fill that component with values that do not have the same gap to each other and set the ChartArea.Area3dStyle.Enable3d property to true, there is almost no impact on the chart until I equalize the gaps between the values in the series.
DataPoint dataPoint1 = new DataPoint(0D, 20D);
DataPoint dataPoint2 = new DataPoint(1D, 30D);
DataPoint dataPoint3 = new DataPoint(200D, 50D);
DataPoint dataPoint4 = new DataPoint(300D, 20D);
DataPoint dataPoint5 = new DataPoint(400D, 0D);
DataPoint dataPoint6 = new DataPoint(500D, 30D);
DataPoint dataPoint7 = new DataPoint(600D, 10D);
DataPoint dataPoint8 = new DataPoint(700D, 10D);
series1.Points.Add(dataPoint1);
series1.Points.Add(dataPoint2);
series1.Points.Add(dataPoint3);
series1.Points.Add(dataPoint4);
series1.Points.Add(dataPoint5);
series1.Points.Add(dataPoint6);
series1.Points.Add(dataPoint7);
series1.Points.Add(dataPoint8);
chartArea1.Area3DStyle.Enable3D = true;
You can set various parameters here. The one that directly makes up for the automtic downscaling with your large x-values is PointDepth
chartArea1.Area3DStyle.Enable3D = true;
chartArea1.Area3DStyle.PointDepth = 999; // pick a value you like
The best way to explore the many wonders of the Chart control is to play with it in the designer. When you have found a good setting you can go to the yourForm.Designer.cs file and look at the generated code; while you are not advised to fool around with it is a valuable resource for many obscure settings..
Unfortunately the maximum PointDepth is 1000 and with x-values larger than 300-500 the 3D-effect is still rather weak. Maybe you can downscale your values?

Drop lines in MSChart

I am using MSChart in my C# program to create line graphs, and am unable to find any options to create "drop lines" i.e. lines dropping down from each data point to the X-Axis.
Can anyone help?
Thanks.
I solved my problem using the LineAnnotation object:
int index = 1;
foreach (DataPoint _point in series1.Points)
{
LineAnnotation annotation = new LineAnnotation();
annotation.LineColor = Color.Black;
annotation.LineWidth = 4;
annotation.LineDashStyle = ChartDashStyle.Dot;
annotation.AxisX = chartArea1.AxisX;
annotation.AxisY = chartArea1.AxisY;
annotation.AnchorX = index;
annotation.AnchorY = 0;
annotation.Height = _point.YValues[0];
annotation.Width = 0;
annotation.IsSizeAlwaysRelative = false;
annotation.ClipToChartArea = "ChartArea1";
chart1.Annotations.Add(annotation);
index++;
}
Funnily enough, the above code behaved strangely when I anchored the annotation to the data point itself, drawing some lines up and some lines down even though all my points are in the same quadrant. After a lot of playing around, I managed to solve the problem by anchoring the annotation to the appropriate "dropped" point on the X-axis.

c# devexpress piechart series point color change

I've made a dynamic 3d piechart using devexpress. I'm really impressed with how good the control feature is. I've hit a little bit of a downer though.
I would like my pie chart points to have different colors that I set in code (this will later be changed by the user using some form of pallet or combo box, not sure yet). Unfortunatly I can't seem to get a color method for the points of my data series.
Here's the code excluding the mass of commented out attempts:
Series series1 = new Series("Series1", ViewType.Pie3D);
chartControl2.Series.Add(series1);
series1.DataSource = chartTable;
series1.ArgumentScaleType = ScaleType.Qualitative;
series1.ArgumentDataMember = "names";
series1.ValueScaleType = ScaleType.Numerical;
series1.ValueDataMembers.AddRange(new string[] { "Value" });
//series1.Label.PointOptions.PointView = PointView.ArgumentAndValues;
series1.LegendPointOptions.PointView = PointView.ArgumentAndValues;
series1.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
series1.LegendPointOptions.ValueNumericOptions.Precision = 0;
// Adjust the value numeric options of the series.
series1.Label.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
series1.Label.PointOptions.ValueNumericOptions.Precision = 0;
// Adjust the view-type-specific options of the series.
((Pie3DSeriesView)series1.View).Depth = 20;
((Pie3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[0]);
((Pie3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[1]);
((Pie3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[2]);
((Pie3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[3]);
((Pie3DSeriesView)series1.View).ExplodedDistancePercentage = 20;
chartControl2.Legend.Visible = true;
So I need something like chartcontrol2.series1.point[0].color = color.blue; something like this.
Drawing in charts when drawing the series points of charts. To do this you should handle the ChartControl.CustomDrawSeriesPoint event, and then you can change some of the drawing parameters using its event args.
check these events to do your functinality..
How to: Custom Paint Series Points
ChartControl.CustomDrawSeries Event
You need to define a chart Palette or use an existing one defined by DevExpress. See this
http://documentation.devexpress.com/#XtraCharts/CustomDocument7434

Categories