I was trying to overlap two chart areas. They would share the same x values, but Y would have different values and scales.
Here is outcome of my code:
As you can see red series is not in alignment with green series.I was searching this site for answers, but couldn't find one that worked. Could someone explain me why they don't align?
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace TestGraph
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
#region Data
// Creating first series
Series s1 = new Series();
s1.Name = "Values";
s1.ChartType = SeriesChartType.Column;
s1.XValueType = ChartValueType.DateTime;
s1.Color = Color.Green;
s1.BorderWidth = 2;
// Hard Coding test values
DataPoint[] values =
{
new DataPoint(new DateTime(2017, 8, 1).ToOADate(), 10),
new DataPoint(new DateTime(2017, 8, 2).ToOADate(), 11),
new DataPoint(new DateTime(2017, 8, 3).ToOADate(), 12),
new DataPoint(new DateTime(2017, 8, 4).ToOADate(), 13),
};
// Adding vales to s1
foreach (DataPoint p in values)
{
s1.Points.Add(p);
}
// Creating second series
Series s2 = new Series();
s2.Name = "Values 2";
s2.ChartType = SeriesChartType.Column;
s2.XValueType = ChartValueType.DateTime;
s2.Color = Color.Red;
s2.BorderWidth = 2;
// Hard Coding test values
DataPoint[] values2 =
{
new DataPoint(new DateTime(2017, 8, 1).ToOADate(), 0.1),
new DataPoint(new DateTime(2017, 8, 2).ToOADate(), -0.2),
new DataPoint(new DateTime(2017, 8, 3).ToOADate(), -0.7),
new DataPoint(new DateTime(2017, 8, 4).ToOADate(), 13),
};
// Adding vales to s2
foreach (DataPoint p in values2)
{
s2.Points.Add(p);
}
#endregion
#region Charts
// Initializing chart
Chart mainChart = new Chart();
ChartArea area = new ChartArea();
ChartArea area2 = new ChartArea();
Controls.Add(mainChart);
mainChart.Dock = DockStyle.Fill;
// Adding areas to mainChart
mainChart.ChartAreas.Add(area);
mainChart.ChartAreas.Add(area2);
// Adding series to areas
s1.ChartArea = area.Name;
s2.ChartArea = area2.Name;
mainChart.Series.Add(s1);
mainChart.Series.Add(s2);
// Aligning areas
// Overlapping area2 with area
area2.AlignmentStyle = AreaAlignmentStyles.All;
area2.AlignmentOrientation = AreaAlignmentOrientations.All;
area2.AlignWithChartArea = area.Name;
// Scale actualization
area2.RecalculateAxesScale();
area.RecalculateAxesScale();
// Defining Y scale
area2.AxisY.Maximum = 2;
area2.AxisY.Minimum = -2;
area2.BackColor = Color.Transparent;
// Disabling unnecessary graphics
area2.BackGradientStyle = GradientStyle.None;
area2.AxisX.IsMarginVisible = false;
area2.AxisX.LabelStyle.Enabled = false;
area2.AxisY.LabelStyle.Enabled = false;
area2.AxisX.Enabled = AxisEnabled.False;
area2.AxisY.Enabled = AxisEnabled.False;
// Resizing chart back to 100%
area.Position = new ElementPosition(0, 0, 100, 100);
#endregion
}
}
}
One of your chart has AxisX.IsMarginVisible set to true, the other to false, hence the mismatch.
However, if you are trying to plot overlapping series, why are you not adding them to the same chart area instead of going through all this trouble?
Related
I'm trying to create a Polar Plot with Oxyplot in my WPF application. I want the MagnitudeAxis to be reversed so I made the StartPosition = 1 and the EndPosition = 0. However this causes the plot not to render. It looks it may be due to the variables a0 and a1 being set to 0 in the UpdateTransform() method in MagnitudeAxis.cs but it may be something else (not exactly sure what all these variables represent).
Here's my code to set up the polar plot:
/// dictionary of angles: magnitudes
dict = {-180: -18, -179: -17.9, ... , 0: 0, ... , 178: -17.8, 179: -17.9}
PlotModel myPlot = new PlotModel
{
Title = "Polar Plot",
PlotType = PlotType.Polar,
PlotAreaBorderThickness = new OxyThickness(0),
};
var series1 = new ScatterSeries
{
Title = "Polar Series",
MarkerType = MarkerType.Circle,
MarkerSize = 3,
MarkerFill = OxyColor.FromRgb(255, 0, 0),
};
var axis1 = new AngleAxis
{
StartPosition = 1,
EndPosition = 0,
StartAngle = 270,
EndAngle = -90,
Title = "Angle",
LabelFormatter = d => $"{d}",
MajorStep = 30,
Minimum = -180,
Maximum = 180,
MinorGridlineStyle = LineStyle.None,
};
var axis2 = new MagnitudeAxis
{
/// here's where I set the Start and End Position
StartPosition = 1,
EndPosition = 0,
MajorStep = 6,
Title = "Magnitude",
MinorGridlineStyle = LineStyle.None,
Minimum = dict.Values.Min();
Maximum = dict.Values.Max()
};
foreach (KeyValuePair<double, double> keyValuePair in dict)
{
series1.Points.Add(new ScatterPoint(keyValuePair.Value, keyValuePair.Key));
}
myPlot.Axes.Add(axis1);
myPlot.Axes.Add(axis2);
myPlot.Series.Add(series1);
This is what I get when the plot tries rendering:
This is what I get when I use default Start/End Positions:
What I want is the default plot with 0 in the center and -18 on the edge instead.
This is my first question ever on SO, so let me know if there's any other information I should provide.
I'm using System.Web.UI.DataVisualization. Charting to create charts in MVC.
I have a chart displaying values in a StackedColumn100 SeriesChartType with the corresponding y-axis values on the primary y-axis on the left side.
Since it is a 100% stacked column series, the primary y-axis is scaled from 0 to 100.
I have then added a secondary series in the form of a Line SeriesChartType tied to a secondary axis (on the right side). I would like this axis to adjust its scale based on the values in the series but it doesn't. No matter what the highest value of this series is, the secondary y-axis also has a scale between 0 to 100.
If I manually set the maximum value for the secondary y-axis the following way:
chart.ChartAreas[0].AxisY2.Maximum = 20;. It works but I don't want to do that since the maximum value can differ greatly based on the search criteria used.
I have really tried to find a solution for this but I can't. According to the documentation and samples it seems that the scale should be based on the series values but I don't get it to work that way. Any help would be greatly appreciated!
Below is a stand alone test function that recreates the problem. I call the function from my view with the following line:
<p><img src="#Url.Action("CreateChart_TestSecondaryAxis")" /> </p>
public FileResult CreateChart_TestSecondaryAxis()
{
System.Web.UI.DataVisualization.Charting.Chart chart = new System.Web.UI.DataVisualization.Charting.Chart();
chart.Width = 800;
chart.Height = 400;
chart.BackColor = Color.FromArgb(211, 223, 240);
chart.BorderlineDashStyle = ChartDashStyle.Solid;
chart.BackSecondaryColor = Color.White;
chart.BackGradientStyle = GradientStyle.TopBottom;
chart.BorderlineWidth = 1;
chart.Palette = ChartColorPalette.BrightPastel;
chart.BorderlineColor = Color.FromArgb(26, 59, 105);
chart.RenderType = RenderType.BinaryStreaming;
chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
ChartArea chartArea = new ChartArea();
chartArea.Name = "TestSecondaryAxis";
chartArea.BackColor = Color.Transparent;
chartArea.AxisX.IsLabelAutoFit = false;
chartArea.AxisY.IsLabelAutoFit = false;
chartArea.AxisX.LabelStyle.Font =
new Font("Verdana,Arial,Helvetica,sans-serif",
8F, FontStyle.Regular);
chartArea.AxisY.LabelStyle.Font =
new Font("Verdana,Arial,Helvetica,sans-serif",
8F, FontStyle.Regular);
chartArea.AxisY.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.Title = "Airport";
chartArea.AxisY.Title = "LandingConf";
chartArea.AxisY.TextOrientation = TextOrientation.Rotated270;
chartArea.AxisX.LabelStyle.IsEndLabelVisible = true;
chart.ChartAreas.Add(chartArea);
Series seriesPrimaryAxisConf3 = new Series();
seriesPrimaryAxisConf3.Name = "Conf 3";
seriesPrimaryAxisConf3.IsValueShownAsLabel = false;
seriesPrimaryAxisConf3.Color = Color.Blue;
seriesPrimaryAxisConf3.ChartType = SeriesChartType.StackedColumn100;
seriesPrimaryAxisConf3.BorderWidth = 2;
seriesPrimaryAxisConf3.ChartArea = "TestSecondaryAxis";
DataPoint point;
for (int i = 1; i < 11; i++)
{
point = new DataPoint();
point.AxisLabel = "Airport" + i.ToString();
point.YValues = new double[] { i };
seriesPrimaryAxisConf3.Points.Add(point);
}
chart.Series.Add(seriesPrimaryAxisConf3);
Series seriesPrimaryAxisConfFull = new Series();
seriesPrimaryAxisConfFull.Name = "Conf Full";
seriesPrimaryAxisConfFull.IsValueShownAsLabel = false;
seriesPrimaryAxisConfFull.Color = Color.Red;
seriesPrimaryAxisConfFull.ChartType = SeriesChartType.StackedColumn100;
seriesPrimaryAxisConfFull.BorderWidth = 2;
seriesPrimaryAxisConfFull.ChartArea = "TestSecondaryAxis";
for (int i = 1; i < 11; i++)
{
point = new DataPoint();
point.AxisLabel = "Airport" + i.ToString();
point.YValues = new double[] { 11-i };
seriesPrimaryAxisConfFull.Points.Add(point);
}
chart.Series.Add(seriesPrimaryAxisConfFull);
Series seriesSecondaryAxisNoOfFlights = new Series();
seriesSecondaryAxisNoOfFlights.Name = "NoOfFLights";
seriesSecondaryAxisNoOfFlights.IsValueShownAsLabel = false;
seriesSecondaryAxisNoOfFlights.Color = Color.Red;
seriesSecondaryAxisNoOfFlights.ChartType = SeriesChartType.Line;
seriesSecondaryAxisNoOfFlights.BorderWidth = 2;
seriesSecondaryAxisNoOfFlights.ChartArea = "TestSecondaryAxis";
for (int i = 1; i < 11; i++)
{
point = new DataPoint();
point.AxisLabel = "Airport" + i.ToString();
point.YValues = new double[] { i };
seriesSecondaryAxisNoOfFlights.Points.Add(point);
}
chart.Series.Add(seriesSecondaryAxisNoOfFlights);
chart.Series["NoOfFLights"].YAxisType = AxisType.Secondary;
chart.ChartAreas["TestSecondaryAxis"].AxisY2.LineColor = Color.Transparent;
chart.ChartAreas["TestSecondaryAxis"].AxisY2.MajorGrid.Enabled = false;
chart.ChartAreas["TestSecondaryAxis"].AxisY2.MajorTickMark.Enabled = false;
MemoryStream ms = new MemoryStream();
chart.SaveImage(ms);
return File(ms.GetBuffer(), #"image/png");
}
MSChart is a nice control but unfortunately Microsoft has always failed to properly document it.
And with the latest changes at MSDN things have gone from bad to worse, so I can't actually point to the rules that go for the various ChartTypes.
In your case I deduct this (rather wacky) rule:
To attach a non 100%-series to an indepently scaled secondary y-axis
it must be the first series but the stacked series still must be added
first.
So, if you want to get a result like this:
..you need to adapt the code. Here are the changes and additions needed..:
First we have to insert the line series at the front but do that after the stack100 series have beeen added..:
chart.Series.Insert(0, seriesSecondaryAxisNoOfFlights); // instead of adding it
Next we need to owner-draw the line as it would get burried under the columns otherwise.
Code the PostPaint event like this:
private void Chart_PostPaint(object sender, ChartPaintEventArgs e)
{
Chart chart = sender as Chart; //*
Series s = chart.Series[0]; // make sure to pick the right one!
Axis ax = chart.ChartAreas[0].AxisX;
Axis ay = chart.ChartAreas[0].AxisY2; // !!
var pts = s.Points.Select(x =>
new PointF((float)ax.ValueToPixelPosition(x.XValue),
(float)ay.ValueToPixelPosition(x.YValues[0])));
using (Pen pen = new Pen(s.Color, s.BorderWidth))
e.ChartGraphics.Graphics.DrawLines(pen, pts.ToArray());
}
For this to work the series need valid x-values. So add this line:
point.XValue = i; // set both x and y-values!
I also added a few nudges to the axis positioning:
ChartArea ca = chart.ChartAreas["TestSecondaryAxis"];
ca.AxisY.Maximum = 100;
ca.AxisX.Minimum = 0.5;
ca.AxisX.IntervalOffset = 0.5;
i need logarithm x-axis based linechart for audio frequency magnitude response for c# winform , i have tested default chart and livechart but c'ant align x axis attached photo like . anybody know please help me.
sorry for my bad english
Live Chart Code :
cartesianChart1.AxisY.Add(new Axis
{
Title = "Gain",
MaxValue = 10,
MinValue = -15,
Separator = new Separator
{
Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(46, 35, 35))
}
});
cartesianChart1.AxisX.Add(new LogarithmicAxis
{
Title = "Freq",
LabelFormatter = (value) => (Math.Pow(10, value).ToString("N0")+"Hz"),
Base = 10,
Separator = new Separator
{
Step=0,
Stroke = new SolidColorBrush(System.Windows.Media.Color.FromRgb(35, 35, 35))
},
});
cartesianChart1.BackColor = System.Drawing.Color.FromArgb(0, 0, 0);
cartesianChart1.DisableAnimations = true;
cartesianChart1.Hoverable = false;
cartesianChart1.DataTooltip = null;
var Datapoint = new ChartValues<ObservablePoint>{
new ObservablePoint(1, 5),
new ObservablePoint(5, -4),
new ObservablePoint(10, 6),
new ObservablePoint(100, 4),
new ObservablePoint(150, 7),
new ObservablePoint(1000, 2),
new ObservablePoint(10000, 8),
new ObservablePoint(15000, 2),
new ObservablePoint(20000, -7),
};
cartesianChart1.Series = new SeriesCollection(Mappers.Xy<ObservablePoint>()
.X(point => Math.Log10(point.X))
.Y(point => point.Y))
{
new LineSeries
{
PointGeometry = null,
PointGeometrySize = 0,
Values = Datapoint,
}
};
Live Chart Display :
Default Chart Code :
var r = new Random();
float val;
var chart = chart1.ChartAreas[0];
chart.AxisX.IntervalType = DateTimeIntervalType.Number;
chart.AxisX.LabelStyle.Format = "";
chart.AxisY.LabelStyle.Format = "";
chart.AxisY.LabelStyle.IsEndLabelVisible = true;
chart.AxisX.Minimum = 0;
chart.AxisX.Maximum = 20000;
chart.AxisY.Minimum = -15;
chart.AxisY.Maximum = 10;
chart.AxisX.Interval = 500;
chart.AxisY.Interval = 3;
chart.BackColor = Color.Black;
chart1.Series.Add("Sakthi");
chart1.Series["Sakthi"].ChartType = SeriesChartType.Spline;
chart1.Series["Sakthi"].Color = Color.Yellow;
chart1.Series["Sakthi"].BorderWidth = 3;
chart1.Series["Sakthi"].BorderColor = Color.Black;
chart1.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(35, 35, 35);
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(35, 35, 35);
chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
chart1.Legends[0].Enabled = false;
chart.AxisY.StripLines.Add(new StripLine
{
BorderDashStyle = ChartDashStyle.Dot,
BorderColor = Color.White,
StripWidth = 0
});
chart1.Series.Clear();
chart1.Series.Add("Sakthi");
chart1.Series["Sakthi"].ChartType = SeriesChartType.Spline;
chart1.Series["Sakthi"].Color = Color.Yellow;
chart1.Series["Sakthi"].BorderWidth = 3;
chart1.Series["Sakthi"].BorderColor = Color.Black;
for (int i = 0; i < 10; i++)
{
val = r.Next(-15, 10);
chart1.Series["Sakthi"].Points.AddXY(i*2000, val);
}
Default Chart Display :
i want this this type x axis label :
Making a chart using secondary axis,
makes my chart primary y-axis is shown with some values which I don't want to have.
Only x-axis and secondary y-axis.
and also the x-axis is drawn without the date values what I've passed.
Code:
chartType2 = GetChartType(worksheet, chartToDraw, endcolcnt, i, chartType2, chartType);
chartType2.UseSecondaryAxis = true;
Scale(headerString, endcolcnt, worksheet, chartType2, stcol, isFieldSame, endcol, stcolumn1, endrow, startRow);
and Scale Function only assigns the header names and all.
Details about the series taken
Output:
Input
Hard to say without more code. What are those functions doing exactly?
Are you trying to just get the axis on the right side? Based on the black chart you posted that would seem like what you are after. You could just do chartType.YAxis.Crosses = eCrosses.Max.
Or do you actually want TWO axes which would require two charts/series? If you want that then you would need to create a second chart based on the first (looks like your function might be doing that) and then add a unique series to each but with a common x-value dataset. Just make sure you add them in the right order.
This shows both scenarios:
[TestMethod]
public void Chart_Secondary_Axis_Test()
{
//http://stackoverflow.com/questions/28540458/using-secondary-axis-for-chart-cause-x-axis-and-primary-y-axis-issue-excel
var existingFile = new FileInfo(#"c:\temp\temp.xlsx");
if (existingFile.Exists)
existingFile.Delete();
using (var pck = new ExcelPackage(existingFile))
{
var wsContent = pck.Workbook.Worksheets.Add("Content");
//Some data
wsContent.Cells["A1"].Value = "A"; wsContent.Cells["B1"].Value = "B"; wsContent.Cells["C1"].Value = "C"; wsContent.Cells["D1"].Value = "D";
wsContent.Cells["A2"].Value = 100; wsContent.Cells["A3"].Value = 400; wsContent.Cells["A4"].Value = 200; wsContent.Cells["A5"].Value = 300; wsContent.Cells["A6"].Value = 600; wsContent.Cells["A7"].Value = 500;
wsContent.Cells["B2"].Value = 300; wsContent.Cells["B3"].Value = 200; wsContent.Cells["B4"].Value = 1000; wsContent.Cells["B5"].Value = 600; wsContent.Cells["B6"].Value = 500; wsContent.Cells["B7"].Value = 200;
wsContent.Cells["D2"].Value = new DateTime(2015, 1, 1); wsContent.Cells["D3"].Value = new DateTime(2015, 1, 2); wsContent.Cells["D4"].Value = new DateTime(2015, 1, 3); wsContent.Cells["D5"].Value = new DateTime(2015, 1, 4); wsContent.Cells["D6"].Value = new DateTime(2015, 1, 5); wsContent.Cells["D7"].Value = new DateTime(2015, 1, 6);
const int dataRow = 7;
const string FORMATDATE = "m/d/yy";
wsContent.Cells[2, 4, dataRow, 4].Style.Numberformat.Format = FORMATDATE;
//Single Axis with intersection on the right
var chart1 = wsContent.Drawings.AddChart("Chart1", eChartType.XYScatterLines);
chart1.SetSize(600, 400);
var serie1 = (ExcelScatterChartSerie)chart1.Series.Add(wsContent.Cells[2, 1, dataRow, 1], wsContent.Cells[2, 4, dataRow, 4]);
serie1.Header = wsContent.Cells[1, 1].Value.ToString();
chart1.YAxis.Crosses = eCrosses.Max;
//Dual Axis
var chart2a = wsContent.Drawings.AddChart("Chart2", eChartType.ColumnStacked);
chart2a.SetSize(600, 400);
chart2a.SetPosition(400, 0);
var serie2a = chart2a.Series.Add(wsContent.Cells[2, 2, dataRow, 2], wsContent.Cells[2, 4, dataRow, 4]);
serie2a.Header = wsContent.Cells[1, 2].Value.ToString();
var chart2b = chart2a.PlotArea.ChartTypes.Add(eChartType.XYScatterLines);
var serie2b = chart2b.Series.Add(wsContent.Cells[2, 1, dataRow, 1], wsContent.Cells[2, 4, dataRow, 4]);
serie2b.Header = wsContent.Cells[1, 1].Value.ToString();
chart2b.UseSecondaryAxis = true; //Flip the axes
pck.Save();
}
}
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;
}