Related
I'm developing a logarithmic graph as shown below:
The labels of each point are located right next to the point, and this is what I do not want, because what I am looking for is that the labels are located at the bottom of the graph, just in the direction on the x axis that corresponds to it.
Its encoding with hard code is as follows:
Series series = Chart1.Series["Series1"];
Series seriesPuntos = new Series();
seriesPuntos.Points.AddXY(76.20, 100.0);
seriesPuntos.Points.AddXY(63.50, 100.0);
seriesPuntos.Points.AddXY(50.80, 100.0);
seriesPuntos.Points.AddXY(38.10, 100.0);
seriesPuntos.Points.AddXY(25.40, 98.6);
seriesPuntos.Points.AddXY(19.05, 90.0);
seriesPuntos.Points.AddXY(12.70, 83.0);
seriesPuntos.Points.AddXY(9.53, 75.9);
seriesPuntos.Points.AddXY(4.75, 59.8);
seriesPuntos.Points.AddXY(2.36, 46.8);
seriesPuntos.Points.AddXY(1.18, 39.3);
seriesPuntos.Points.AddXY(0.85, 36.8);
seriesPuntos.Points.AddXY(0.60, 30.7);
seriesPuntos.Points.AddXY(0.42, 27.1);
seriesPuntos.Points.AddXY(0.30, 25.7);
seriesPuntos.Points.AddXY(0.25, 24.0);
seriesPuntos.Points.AddXY(0.18, 21.9);
seriesPuntos.Points.AddXY(0.15, 20.6);
seriesPuntos.Points.AddXY(0.10, 19.7);
seriesPuntos.Points.AddXY(0.074, 18.3);
Chart1.Series.Add(seriesPuntos);
Chart1.Series[1].XValueType = ChartValueType.Double;
Chart1.Series[1].YValueType = ChartValueType.Double;
Chart1.Series[0].ChartType = SeriesChartType.Line;
Chart1.Series[1].ChartType = SeriesChartType.Point;
Chart1.Series[0].Color = Color.DarkRed;
Chart1.Series[0].BorderWidth = 1;
Chart1.Series[0].BorderDashStyle = ChartDashStyle.Dash;
Chart1.Series[1].Color = Color.DarkRed;
Chart1.Series[1].BorderWidth = 15;
Chart1.ChartAreas[0].BorderWidth = 1;
Chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
Chart1.ChartAreas[0].AxisY.Interval = 2;
Chart1.ChartAreas[0].AxisX.Interval = 1;
Chart1.ChartAreas[0].AxisY.Minimum = 0;
Chart1.ChartAreas[0].AxisY.Maximum = 100;
Chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 90;
series.Points.AddXY(76.20, 100.0);
series.Points.AddXY(63.50, 100.0);
series.Points.AddXY(50.80, 100.0);
series.Points.AddXY(38.10, 100.0);
series.Points.AddXY(25.40, 98.6);
series.Points.AddXY(19.05, 90.0);
series.Points.AddXY(12.70, 83.0);
series.Points.AddXY(9.53, 75.9);
series.Points.AddXY(4.75, 59.8);
series.Points.AddXY(2.36, 46.8);
series.Points.AddXY(1.18, 39.3);
series.Points.AddXY(0.85, 36.8);
series.Points.AddXY(0.60, 30.7);
series.Points.AddXY(0.42, 27.1);
series.Points.AddXY(0.30, 25.7);
series.Points.AddXY(0.25, 24.0);
series.Points.AddXY(0.18, 21.9);
series.Points.AddXY(0.15, 20.6);
series.Points.AddXY(0.10, 19.7);
series.Points.AddXY(0.074, 18.3);
Chart1.Series[0].XValueType = ChartValueType.Double;
Chart1.Series[0].YValueType = ChartValueType.Double;
Chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 90;
Chart1.ChartAreas[0].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep90;
Chart1.ChartAreas[0].AxisX.IsLogarithmic = true;
Chart1.ChartAreas[0].AxisY.Title = "% QUE PASA EN PESO";
Chart1.ChartAreas[0].AxisY.TitleFont = new Font("Roboto", 11, FontStyle.Bold);
Chart1.ChartAreas[0].AxisX.Title = "ABERTURA (mm)";
Chart1.ChartAreas[0].AxisX.TitleFont = new Font("Roboto", 11, FontStyle.Bold);
Chart1.Series[0].IsValueShownAsLabel = true;
Chart1.Series[0].LabelBackColor = Color.White;
Chart1.Series[0].LabelAngle = 90;
Chart1.Series[0].IsXValueIndexed = true;
Chart1.Series[1].IsXValueIndexed = true;
View:
<asp:Chart ID="Chart1" runat="server" BorderlineWidth="14" Width="990px" Height="450" class="card-img-top" Style="width: auto; !important">
<Series>
<asp:Series Name="Series1" ChartType="Line"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
<Titles>
<asp:Title Font="Roboto, 12pt, style=Bold" Name="Title1" Text="CURVA GRANULOMÉTRICA">
<Position Height="3.862135" Width="92" X="8" Y="1" />
</asp:Title>
</Titles>
</asp:Chart>
What I'm looking for is that the labels of each point are located at the bottom of the graph as shown below:
Your example don't seem to work, at least in my machine (and I found some indications online as well). You can't use AxisX.IsLogarithmic with Series.IsXValueIndexed.
I don't know why your code has two series with the same values.
If you want to use a line and highlight the points you should use the MarkerXXX properties:
series.ChartType = SeriesChartType.Line;
series.MarkerColor = Color.Red;
series.MarkerStyle = MarkerStyle.Circle;
series.MarkerSize = 4;
I don't think there is any way of doing what you want "off the shelf".
You have to use AxisX.CustomLabels. Something like:
var series = Chart1.Series["Series1"];
series.Points.AddXY(76.20, 100.0);
series.Points.AddXY(63.50, 100.0);
series.Points.AddXY(50.80, 100.0);
series.Points.AddXY(38.10, 100.0);
series.Points.AddXY(25.40, 98.6);
series.Points.AddXY(19.05, 90.0);
series.Points.AddXY(12.70, 83.0);
series.Points.AddXY(9.53, 75.9);
series.Points.AddXY(4.75, 59.8);
series.Points.AddXY(2.36, 46.8);
series.Points.AddXY(1.18, 39.3);
series.Points.AddXY(0.85, 36.8);
series.Points.AddXY(0.60, 30.7);
series.Points.AddXY(0.42, 27.1);
series.Points.AddXY(0.30, 25.7);
series.Points.AddXY(0.25, 24.0);
series.Points.AddXY(0.18, 21.9);
series.Points.AddXY(0.15, 20.6);
series.Points.AddXY(0.10, 19.7);
series.Points.AddXY(0.074, 18.3);
series.XValueType = ChartValueType.Double;
series.YValueType = ChartValueType.Double;
series.ChartType = SeriesChartType.Line;
series.Color = Color.DarkRed;
series.BorderWidth = 1;
series.BorderDashStyle = ChartDashStyle.Dash;
series.MarkerColor = Color.Red;
series.MarkerStyle = MarkerStyle.Circle;
series.MarkerSize = 4;
var chartArea = Chart1.ChartAreas[0];
chartArea.BorderWidth = 1;
chartArea.BorderDashStyle = ChartDashStyle.Solid;
chartArea.AxisY.Interval = 2;
chartArea.AxisY.Minimum = 0;
chartArea.AxisY.Maximum = 100;
chartArea.AxisY.Title = "% QUE PASA EN PESO";
chartArea.AxisY.TitleFont = new Font("Roboto", 11, FontStyle.Bold);
chartArea.AxisX.LabelStyle.Angle = -90;
chartArea.AxisX.Title = "ABERTURA (mm)";
chartArea.AxisX.TitleFont = new Font("Roboto", 11, FontStyle.Bold);
chartArea.AxisX.IsLogarithmic = true;
chartArea.AxisX.MinorGrid.Interval = 1;
chartArea.AxisX.MinorGrid.Enabled = true;
//Axis is in log, so the CustomLabels fromPosition and toPosition should be as well - This gave me a small headache
var logBase = Chart1.ChartAreas[0].AxisX.LogarithmBase;
//Define the interval to show the text
var customLabelInterval = Math.Log(0.01, logBase);
foreach (var seriesPoint in series.Points)
{
chartArea.AxisX.CustomLabels.Add(Math.Log(seriesPoint.XValue, logBase) - customLabelInterval, Math.Log(seriesPoint.XValue, logBase) + customLabelInterval, seriesPoint.XValue.ToString(CultureInfo.CurrentCulture));
}
Resulting in
I use a line chart with double in Y axis and DateTime in X axis. My plot has only intraday data: I have one point each minutes between 8 am and 10 pm.
I want to underline certain periods of the plot. The first period begins at 8:50 and continues during 20 minutes. For this I use a stripLine with the following code:
var stripLine = new StripLine();
stripLine.BackColor = Color.White;
stripLine.BackGradientStyle = GradientStyle.TopBottom;
stripLine.BackImageTransparentColor = Color.White;
stripLine.BackSecondaryColor = Color.Transparent;
stripLine.Interval = 1;
stripLine.IntervalType = DateTimeIntervalType.Days;
stripLine.IntervalOffset = 50;
stripLine.IntervalOffsetType = DateTimeIntervalType.Minutes;
stripLine.StripWidth = 20;
stripLine.StripWidthType= DateTimeIntervalType.Minutes;
chartArea.AxisX.StripLines.Add(stripLine);
However I do not get the right result. Indeed, all my chart area is underlined by the strip line..
Here is a plot to illustrate what I want to achieve:
Your question is a bit obscure: your code is striplining the area vertically from 8:50 to 9:10 A.M.
Do you want to create Stripline every (x):50 to (x+1):10 ?
for(int i=0;i<24;i++)
{
var stripLine = new StripLine();
stripLine.BackColor = Color.White;
stripLine.BackGradientStyle = GradientStyle.TopBottom;
stripLine.BackImageTransparentColor = Color.White;
stripLine.BackSecondaryColor = Color.Transparent;
stripLine.Interval = (double)i;
stripLine.IntervalType = DateTimeIntervalType.Hours;
stripLine.IntervalOffset = 50;
stripLine.IntervalOffsetType = DateTimeIntervalType.Minutes;
stripLine.StripWidth = 20;
stripLine.StripWidthType = DateTimeIntervalType.Minutes;
Chart1.ChartAreas[0].AxisX.StripLines.Add(stripLine);
}
Should work.
Do you want to show the StripLine exactly at the points you showed?
var stripLine = new StripLine();
stripLine.BackColor = Color.White;
stripLine.BackGradientStyle = GradientStyle.TopBottom;
stripLine.BackImageTransparentColor = Color.White;
stripLine.BackSecondaryColor = Color.Transparent;
stripLine.Interval = 9;
stripLine.IntervalType = DateTimeIntervalType.Hours;
stripLine.IntervalOffset = 28;
stripLine.IntervalOffsetType = DateTimeIntervalType.Minutes;
stripLine.StripWidth = 8;
stripLine.StripWidthType= DateTimeIntervalType.Seconds;
chartArea.AxisX.StripLines.Add(stripLine);
Is the right solution.
A StripLine is a line and it will only allow you the add colored rectangles.
To create an area that follows your spline curve you need to either
draw it in the PostPaint event
or use an extra Series of type SplineArea
Here is the 2nd way:
..
Series s3 = chart.Series.Add("S3 ");
s1.ChartType = SeriesChartType.Spline;
s2.ChartType = SeriesChartType.Line;
s3.ChartType = SeriesChartType.SplineArea;
s2.Color = Color.Red;
s3.Color = Color.FromArgb(55, Color.RosyBrown);
for (int i = 0; i < 50; i++)
{
s1.Points.AddXY(i,20 - rnd.Next(10) );
s2.Points.AddXY(i,17);
if (i > 10 && i < 20) s3.Points.AddXY(i, s1.Points[i].YValues[0]);
}
I need to Export my Chart as an image without showing it first in WPF. So i built the Chart in Code:
public void CreateHistogram(CalcRepository cr, int i)
{
Chart chart = new Chart();
chart.Width = 300;
chart.Height = 200;
chart.ScrollingEnabled = false;
chart.AnimationEnabled = false;
chart.TrendLines.Add(new TrendLine{Value = cr.Mean,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines.Add(new TrendLine{Value = cr.ChartTrippleNegativeStdDeviation,Orientation = System.Windows.Controls.Orientation.Vertical,LineStyle = LineStyles.Dashed});chart.TrendLines.Add(new TrendLine{Value = cr.ChartTripplePositiveStdDeviation,Orientation = System.Windows.Controls.Orientation.Vertical,LineStyle = LineStyles.Dashed});
chart.TrendLines.Add(new TrendLine{Value = cr.UpperSpecificationLimit,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines.Add(new TrendLine{Value = cr.LowerSpecificationLimit,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines[0].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[1].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[2].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[3].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[4].SetValue(Canvas.ZIndexProperty, 40);
chart.DataPointWidth = cr.DataPointWidth;
chart.Visibility = Visibility.Visible;
Axis x = new Axis();
x.AxisMaximum = cr.VisUpperBound;
x.AxisMinimum = cr.VisLowerBound;
x.AxisType = AxisTypes.Primary;
CustomAxisLabels cal = new CustomAxisLabels();
cal.Labels.Add(new CustomAxisLabel {From = cr.Mean, To = cr.Mean, Text = "Mean"});
cal.Labels.Add(new CustomAxisLabel {From = cr.ChartTrippleNegativeStdDeviation,To = cr.ChartTrippleNegativeStdDeviation,Text = "LCL"});
cal.Labels.Add(new CustomAxisLabel{From = cr.ChartTripplePositiveStdDeviation,To = cr.ChartTripplePositiveStdDeviation,Text= "UCL"});
cal.Labels.Add(new CustomAxisLabel {From = cr.UpperSpecificationLimit, To = cr.UpperSpecificationLimit , Text = "USL"});
cal.Labels.Add(new CustomAxisLabel {From = cr.LowerSpecificationLimit, To = cr.LowerSpecificationLimit, Text = "LSL"});
cal.FontSize = 10;
cal.Angle = 0;
cal.FontColor = new SolidColorBrush(Colors.Black);
cal.Enabled = true;
x.CustomAxisLabels.Add(cal);
chart.AxesX.Add(x);
var ds = new DataSeries();
var dpc = new DataPointCollection(cr.HistogramValues);
ds.DataPoints = dpc;
chart.Series.Add(ds);
ds.ZIndex = 1;
ds.Bevel = false;
ds.ShadowEnabled = false;
ds.LightingEnabled = false;
ds.Color = new SolidColorBrush(Colors.SteelBlue);
chart.BeginInit();
chart.EndInit();
chart.Measure(new Size(300, 200));
chart.Arrange(new Rect(0, 0, 300, 200));
chart.UpdateLayout();
ExportToPng(new Uri("C:\\" + i + ".png"), chart);
}
everything works fine, except the custom Axis Labels are missing. This is how the Output looks like:
As you can see, there is even space allocated for the CustomAxis Labels but they are not shown. Anyone got an idea?
Hint: AnimationEnabled has to be set false otherwise the series is not rendered yet when the image is taken - took me a long time to figure that out.
I found already a solution:
When exceeding the bounds, the values are set to Double.NaN. I found out, that the creation of all Labels fails, if any value in the Collections Double.Nan or Double.Infinity - Seems lika a bug in visifire.
I solved it by adding each Label in its seperate Collection.
c# mschart vs2010 .net4
chart1.Series[0].Points.AddXY(0, 1);
chart1.Series[0].Points.AddXY(7, 1;
chart1.Series[0].Points.AddXY(8,1);
i was hoping that the 3 points looks like this
. . .
but it turned out like this
. . .
Why?
Thank you
code of chart
chartArea1.AxisX.InterlacedColor = System.Drawing.SystemColors.ControlLight;
chartArea1.AxisX.Interval = 1D;
chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisX.IntervalOffset = 1D;
chartArea1.AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
chartArea1.AxisX.IsInterlaced = true;
chartArea1.AxisX.IsLabelAutoFit = false;
chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chartArea1.AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDotDot;
chartArea1.AxisX.MajorTickMark.LineColor = System.Drawing.Color.Maroon;
chartArea1.AxisX.ScrollBar.LineColor = System.Drawing.Color.White;
chartArea1.AxisY.ArrowStyle = System.Windows.Forms.DataVisualization.Charting.AxisArrowStyle.SharpTriangle;
chartArea1.AxisY.InterlacedColor = System.Drawing.Color.WhiteSmoke;
chartArea1.AxisY.Interval = 1D;
chartArea1.AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
chartArea1.AxisY.IsInterlaced = true;
chartArea1.AxisY.IsLabelAutoFit = false;
chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Lucida Grande", 8F);
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chartArea1.AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDot;
chartArea1.AxisY.ScaleView.MinSizeType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
chartArea1.CursorX.IsUserEnabled = true;
chartArea1.CursorX.IsUserSelectionEnabled = true;
chartArea1.CursorY.IsUserEnabled = true;
chartArea1.CursorY.IsUserSelectionEnabled = true;
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Location = new System.Drawing.Point(-4, 0);
this.chart1.Margin = new System.Windows.Forms.Padding(0);
this.chart1.Name = "chart1";
series1.BorderWidth = 3;
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
series1.Font = new System.Drawing.Font("Calibri", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
series1.IsXValueIndexed = true;
series1.LabelBorderWidth = 2;
series1.MarkerColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
series1.Name = "Series1";
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.UInt32;
series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.UInt32;
this.chart1.Series.Add(series1);
this.chart1.Size = new System.Drawing.Size(1031, 618);
this.chart1.TabIndex = 5;
Found the problem.
series1.IsXValueIndexed = true;
this is the reason that happened.
it should be false.
thanx for everyone's attention.
I guess you should use empty DataPoints, (see http://msdn.microsoft.com/en-us/library/dd456677.aspx )
Using the IsEmpty property, this would lead to the following code.
( DataManipulator.InsertEmptyPoints should require less code, but I did not test it yet )
chart1.Series[0].Points.Add(new DataPoint(0,1));
chart1.Series[0].Points.Add(new DataPoint(1,0){IsEmpty=true});
chart1.Series[0].Points.Add(new DataPoint(2,0){IsEmpty=true});
chart1.Series[0].Points.Add(new DataPoint(3,0){IsEmpty=true});
chart1.Series[0].Points.Add(new DataPoint(4,0){IsEmpty=true});
chart1.Series[0].Points.Add(new DataPoint(5,0){IsEmpty=true});
chart1.Series[0].Points.Add(new DataPoint(6,0){IsEmpty=true});
chart1.Series[0].Points.Add(new DataPoint(7,1));
chart1.Series[0].Points.Add(new DataPoint(8,1));
I'm trying to make a bar graph, which have to show a bar graph of quality of some goods. My question is about how to make it happen. I'm not sure that the chart control can handle the criterias I want done.
If you imagine that you have a default product, and you want the quality of the barcode. The quality is describe from A(highest) to F(lowest). The output on the graph should be as followed.
http://billedeupload.dk/upload/files/2011-11/f4e132dd.jpg
The understanding of the graph is that it's showing you the quality of the barcode in as a whole, and individually as for example the quality "A". You can see how good the quality of "A" are, compared to the whole.
Can you do this i visual studio c#? And how?
Im using a winform! ;)
Edited:
I want to make it as a Stacked Bargraph. <-- answer to my own question.
Anybody who have a code example for newbies to coding?
Thanks!
The project is old, but I think the source code will help.
WpfSimpleChart
http://wpfsimplechart.codeplex.com/
You should refine your question yet, whether you want to do wpf or winforms.
EDIT
After refining the question, here is a cool charting lib for winforms.
ZedGraph
A flexible charting library for .NET
http://www.codeproject.com/KB/graphics/zedgraph.aspx
I am just getting back into MSChart, so I'll share my findings in hopes that it helps you (and you will check my answer as the correct answer)
I am using LINQPad (http://www.linqpad.net/) to learn MSChart. It is the fastest tool to write C# and render images. I was using Visual Studio, but it takes too much time to build the solution so I can see the results of my changes. I am 'hacking' at MSChart, so I needed faster responses.
I was following the tutorial at http://msdn.microsoft.com/en-us/library/dd489237.aspx to create my LINQPad C# program.
I hope this helps. You could just take my createChart function and drop it in your WinForms project. Take a look at the drawIt method, that is what brings together the stream into an actual graphic.
FYI,
I am using SysDraw = System.Drawing
SysDraw.Color blueStart = SysDraw.Color.FromArgb(124,195,215);
SysDraw.Color blueEnd = SysDraw.Color.FromArgb(74,166,192);
SysDraw.Color grayStart = SysDraw.Color.FromArgb(153,153,153);
SysDraw.Color grayEnd = SysDraw.Color.FromArgb(208,210,211);
SysDraw.Color orangeStart = SysDraw.Color.FromArgb(252,165,107);
SysDraw.Color orangeEnd = SysDraw.Color.FromArgb(255,104,4);
void Main()
{
//chart1 is from Microsoft's sample site
// other charts are using http://msdn.microsoft.com/en-us/library/dd489237.aspx
Chart chart1 = createChart1();
Chart chart2= createChart2(42, "Chart 2");
Chart chart3 = createChart2(99, "Chart 3");
Chart chart4 = createChart2(11, "Chart 4");
drawIt(chart2, chart2.Name);
drawIt(chart3, chart3.Name);
drawIt(chart4, chart4.Name);
drawIt(chart1, chart1.Name);
}
private void drawIt(Chart drawChart, string name)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
drawChart.SaveImage(ms,SysDraw.Imaging.ImageFormat.Png);
SysDraw.Bitmap outImage = new SysDraw.Bitmap(ms);
outImage.Dump(name);
}
private void drawIt(string imageFilePath)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
SysDraw.Bitmap outImage = new SysDraw.Bitmap(imageFilePath);
outImage.Dump(imageFilePath);
}
private Chart createChart2(double dataPointYvalue, string chartName)
{
string chartAreaName ="Area 1";
// Chart
// --------------------------------
Chart results = new Chart();
results.Name = chartName;
results.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
results.BorderSkin.SkinStyle = BorderSkinStyle.None;
SysDraw.Size size1 = new SysDraw.Size(480,30);
results.Size = size1;
// ChartAreas collection
// --------------------------------
ChartArea area1 =new ChartArea(chartAreaName);
area1.Area3DStyle.Enable3D=false;
//area1.Area3DStyle.Enable3D=true;
area1.Area3DStyle.WallWidth=10;
//area1.Area3DStyle.Inclination=10;
//area1.Area3DStyle.Perspective = 10;
area1.Area3DStyle.Rotation=1;
//area1.BorderDashStyle = ChartDashStyle.DashDot;
area1.BackGradientStyle = GradientStyle.TopBottom;
area1.BackColor = grayStart;
area1.BackSecondaryColor = grayEnd;
// Axes under Area collection
Axis axisX = new Axis();
axisX.LabelStyle.Interval = 1;
axisX.Title ="x axis";
axisX.IsMarginVisible=false;
axisX.Enabled = AxisEnabled.False;
Axis axisY = new Axis();
axisY.Title = "y axis";
axisY.IsMarginVisible=true;
axisY.Enabled = AxisEnabled.False;
area1.AxisX = axisX;
area1.AxisY = axisY;
results.ChartAreas.Add(area1);
// Series Collection Editor
// --------------------------------
Series series1 = new Series("Series 1");
series1.ChartArea = chartAreaName;
series1.ChartType = SeriesChartType.Bar;
series1.CustomProperties="DrawingStyle=Cylinder";
series1.Name = "BarChart";
series1.BackGradientStyle = GradientStyle.TopBottom;
series1.Color=blueStart;
series1.BackSecondaryColor = blueEnd;
// series1.BorderDashStyle= ChartDashStyle.DashDotDot;
// series1.BorderColor = SysDraw.Color.Red;
//series1.Points.AddY(42);
DataPoint dp = new DataPoint();
dp.Name="MyPoint";
dp.YValues= new double[]{dataPointYvalue};
series1.Points.Add(dp);
results.Series.Add(series1);
// Legend
// --------------------------------
// Legend legend = new Legend("Chart 2 Legend");
// legend.DockedToChartArea = "Chart 2 Area 1";
// legend.Docking = Docking.Right;
// legend.IsDockedInsideChartArea = true;
// results.Legends.Add(legend);
// series1.Legend = "Chart 2 Legend"; //You can assign each series to a different legend.
// Title
// --------------------------------
Title title = new Title(string.Format("Your whatever is {0}",dp.YValues[0]));
title.Docking = Docking.Right;
title.TextOrientation = TextOrientation.Horizontal;
//title.DockedToChartArea = chartAreaName;
//results.Titles.Add(title);
// Annotations
// --------------------------------
ArrowAnnotation arrowAnnt = new ArrowAnnotation();
arrowAnnt.AnchorDataPoint=dp;
arrowAnnt.Height=-5;
arrowAnnt.Width=0;
arrowAnnt.AnchorOffsetY=-2.5;
arrowAnnt.SmartLabelStyle.IsOverlappedHidden = false;
TextAnnotation textAnnt = new TextAnnotation();
textAnnt.AnchorDataPoint = dp;
textAnnt.AnchorOffsetX = -10;
textAnnt.ForeColor=SysDraw.Color.White;
textAnnt.Text = dp.YValues[0].ToString();
//results.Annotations.Add(arrowAnnt);
results.Annotations.Add(textAnnt);
return results;
}
private Chart createChart1()
{
Title title1 = new Title();
ChartArea chartArea1 = new ChartArea();
Legend legend1 = new Legend();
Series series1 = new Series();
DataPoint dataPoint1 = new DataPoint(0, 6);
DataPoint dataPoint2 = new DataPoint(0, 9);
DataPoint dataPoint3 = new DataPoint(0, 5);
DataPoint dataPoint4 = new DataPoint(0, 7.5);
DataPoint dataPoint5 = new DataPoint(0, 5.6999998092651367);
DataPoint dataPoint6 = new DataPoint(0, 7);
DataPoint dataPoint7 = new DataPoint(0, 8.5);
Series series2 = new Series();
DataPoint dataPoint8 = new DataPoint(0, 6);
DataPoint dataPoint9 = new DataPoint(0, 9);
DataPoint dataPoint10 = new DataPoint(0, 2);
DataPoint dataPoint11 = new DataPoint(0, 7);
DataPoint dataPoint12 = new DataPoint(0, 3);
DataPoint dataPoint13 = new DataPoint(0, 5);
DataPoint dataPoint14 = new DataPoint(0, 8);
Series series3 = new Series();
DataPoint dataPoint15 = new DataPoint(0, 4);
DataPoint dataPoint16 = new DataPoint(0, 2);
DataPoint dataPoint17 = new DataPoint(0, 1);
DataPoint dataPoint18 = new DataPoint(0, 3);
DataPoint dataPoint19 = new DataPoint(0, 2);
DataPoint dataPoint20 = new DataPoint(0, 3);
DataPoint dataPoint21 = new DataPoint(0, 5);
Chart results = new Chart();
//((System.ComponentModel.ISupportInitialize)(results)).BeginInit();
//
// resulting chart
//
results.BackColor = System.Drawing.Color.WhiteSmoke;
results.BackGradientStyle = GradientStyle.TopBottom;
results.BackSecondaryColor = System.Drawing.Color.White;
results.BorderlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
results.BorderlineDashStyle = ChartDashStyle.Solid;
results.BorderlineWidth = 2;
results.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chartArea1.Area3DStyle.Enable3D = true;
chartArea1.Area3DStyle.Inclination = 15;
chartArea1.Area3DStyle.IsClustered = false;
chartArea1.Area3DStyle.IsRightAngleAxes = false;
chartArea1.Area3DStyle.PointGapDepth = 0;
chartArea1.Area3DStyle.Rotation = 10;
chartArea1.Area3DStyle.WallWidth = 0;
chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
chartArea1.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.BackColor = System.Drawing.Color.WhiteSmoke;
chartArea1.BackSecondaryColor = System.Drawing.Color.White;
chartArea1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
chartArea1.Name = "Default";
chartArea1.ShadowColor = System.Drawing.Color.Transparent;
results.ChartAreas.Add(chartArea1);
results.Cursor = System.Windows.Forms.Cursors.Hand;
legend1.BackColor = System.Drawing.Color.Transparent;
legend1.Enabled = false;
legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
legend1.IsTextAutoFit = false;
legend1.Name = "Default";
results.Legends.Add(legend1);
results.Location = new System.Drawing.Point(16, 53);
results.Name = "chart1";
series1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
series1.ChartArea = "Default";
series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
series1.Legend = "Default";
series1.Name = "Default";
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);
// series2.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
// series2.ChartArea = "Default";
// series2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(252)))), ((int)(((byte)(180)))), ((int)(((byte)(65)))));
// series2.Legend = "Default";
// series2.Name = "Series2";
// series2.Points.Add(dataPoint8);
// series2.Points.Add(dataPoint9);
// series2.Points.Add(dataPoint10);
// series2.Points.Add(dataPoint11);
// series2.Points.Add(dataPoint12);
// series2.Points.Add(dataPoint13);
// series2.Points.Add(dataPoint14);
// series3.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
// series3.ChartArea = "Default";
// series3.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(224)))), ((int)(((byte)(64)))), ((int)(((byte)(10)))));
// series3.Legend = "Default";
// series3.Name = "Series3";
// series3.Points.Add(dataPoint15);
// series3.Points.Add(dataPoint16);
// series3.Points.Add(dataPoint17);
// series3.Points.Add(dataPoint18);
// series3.Points.Add(dataPoint19);
// series3.Points.Add(dataPoint20);
// series3.Points.Add(dataPoint21);
results.Series.Add(series1);
// results.Series.Add(series2);
// results.Series.Add(series3);
results.Size = new System.Drawing.Size(412, 296);
results.TabIndex = 1;
title1.Font = new System.Drawing.Font("Trebuchet MS", 14.25F, System.Drawing.FontStyle.Bold);
title1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
title1.Name = "Title1";
title1.ShadowColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
title1.ShadowOffset = 3;
title1.Text = "3D Cylinder";
results.Titles.Add(title1);
SysDraw.Size mySize = new SysDraw.Size(480, 170);
results.Size = mySize;
return results;
}