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..
Related
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
I have three signals (volgate, current, and energy) referred to the same period. I print data on two graphs: one with voltage (blue) and current (red) and the other with only energy (orange). They are two different graphs, but in practice, they share the same X-axis.
I have two cursor synchronized with the mouse movement that is acting as one cursor for the two graphs and a tooltip based on cursor position shows the currently selected values for the three signals (all the three series have IsXValueIndexed = true with interval = 1). As you can see they work well:
I have two problems:
1) when I start to make zoom they start to differ in GRID ALIGNMENT and SIZE of the chart area. After register always the last point with the "Changing" event, when the user releases the mouse left button "Change" event fires and did the following work: I force the zoom on the opposite graph base on source name.
dlChart_SelectionRangeChange(object sender, CursorEventArgs e){
var source = sender as Chart;
double sp = selection_point.getStartPoint();
double ep = selection_point.getEndPoint();
double tmp = 0;
if (sp == ep)
return;
if (sp > ep)
{// zoom contrario
tmp = sp;
sp = ep;
ep = tmp;
}
switch (source.ChartAreas[0].Name)
{
case CHARTAREA1_NAME:
dlChart2.ChartAreas[0].AxisX.ScaleView.Zoom(sp, ep);
break;
case CHARTAREA2_NAME:
dlChart.ChartAreas[0].AxisX.ScaleView.Zoom(sp, ep);
break;
default: break;
}
}
Following image describe the problem:
2) after zooming in one chart a scrollbar appear, and at this point, user can change the chart view on only one chart. I want to scroll the same way also the other chart.
I always want that the two charts behave like one chart.
I recommend using only one chart. You can add a 2nd ChartArea to it and make it the one your 3rd series is using.
Given your identical x-axes this should be the simplest and cleanest solution.
To enable scrolling, as usual one needs to set these properties:
ChartArea ca1 = chart1.ChartAreas[0];
ChartArea ca2 = chart1.ChartAreas[1];
Axis ax1 = ca1.AxisX;
Axis ax2 = ca2.AxisX;
series3.ChartArea = ca2.Name;
ax1.ScaleView.Zoomable = true;
ax2.ScaleView.Zoomable = true;
ca1.CursorX.IsUserSelectionEnabled = true;
ca2.CursorX.IsUserSelectionEnabled = true;
To keep two ChartAreas in synch this should be enough:
private void chart1_AxisViewChanged(object sender, ViewEventArgs e)
{
ChartArea ca1 = chart1.ChartAreas[0];
ChartArea ca2 = chart1.ChartAreas[1];
Axis ax1 = ca1.AxisX;
Axis ax2 = ca2.AxisX;
if (e.Axis== ax1) { ax2.ScaleView.Size = ax1.ScaleView.Size;
ax2.ScaleView.Position = ax1.ScaleView.Position; }
if (e.Axis== ax2) { ax1.ScaleView.Size = ax2.ScaleView.Size;
ax1.ScaleView.Position = ax2.ScaleView.Position; }
}
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.
So I'm using Windows Forms Chart to generate graphs containing several lines that can create some clutter on the graph and need something to differentiate them other than color. There are too many points to using dotted or dashed lines as there is no observable difference between that and a continuous line. So what I'm hoping to do is to get markers with various shapes to show up on the lines like in Excel, for instance. Right now I'm have it coded like this
myChart.Series["MySeries"].ChartType = SeriesChartType.FastLine;
myChart.Series["MySeries"].MarkerStyle = MarkerStyle.Diamond;
What this does is put a diamond in the legend over that line, but it doesn't put diamonds on the actual line that is in the chart itself. Changing the marker size doesn't make a difference, unfortunately, and neither does changing the marker color. Is there a way to get that to happen. Thanks for reading, and any help you have.
EDIT:
Heres the relevant code.
Its data is held in a class that is the value-peice of a dictionary.
The class contains a list of doubles.
public void Charter(Color colorOfLine)
{
double xValue;
double yValue;
myChart.Series.Add("MySeries");
myChart.Series["MySeries"].ChartType.FastLine;
myChart.Series["MySeries"].ChartArea = "ChartArea1";
myChart.Series["MySeries"].Color = colorOfLine;
myChart.Series["MySeries"].MarkerStyle = MarkerStyle.Diamond;
myChart.Series["MySeries"].MarkerColor = Color.Black;
myChart.Series["MySeries"].MarkerSize = 5;
myChart.Series["MySeries"].MarkerBoarderColor = Color.DeepPink;
foreach (KeyValuePair<int, MyClass> Pair in MyDictionary)
{
xValue = Pair.Value.MyClassList[0];
yValue = Pair.Value.MyClassList[1];
myChart.Series["MySeries"].Points.AddXY(xValue, yValue);
}
}
I should add that I've played around with the MarkerStep, and MarkerBoarderWidth as well, all to no benefit. The issue seems to be that the marker simply isn't appearing on the actual lines in the chart itself. Also I'm using Visual Studio 2010 Express for what its worth. Thanks again for reading.
Use Line. Don't use FastLine. FastLine won't generate markers for you.
myChart.Series["MySeries"].ChartType = SeriesChartType.Line
Set the MarkerSize to something bigger:
myChart.Series["MySeries"].MarkerSize = 4;
ETA:
You may also need to set the color of the marker:
myChart.Series["MySeries"].MarkerColor = Color.Blue;
myChart.Series["MySeries"].Color = Color.Blue;
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