Delete annotations from the map - c#

How could i delete annotations from the map after chosing the new one ?
So let's say i have chosen pin on the X and Y coordinates and would like to move this pin to another place without adding the new one.
Also simply map.RemoveAnnotations(); does not work.
Here is a code which depends on it:
map = new MKMapView(new CGRect(0, 74 + point * 13, UIScreen.MainScreen.Bounds.Width, (UIScreen.MainScreen.Bounds.Height - (74 + point * 20))));
map.UserInteractionEnabled = true;
map.ZoomEnabled = true;
map.ScrollEnabled = true;
map.MapType = MKMapType.Standard;
map.ShowsUserLocation = true;
var longTap = new UILongPressGestureRecognizer() { };
longTap.AddTarget(() => AddPin(longTap, slider.Value));
longTap.MinimumPressDuration = 2.0;
map.AddGestureRecognizer(longTap);
map.GetViewForAnnotation += (mapView, annotation) =>
{
anView = new MKAnnotationView(annotation, Resources.kClusterAnnotationId);
anView.ClipsToBounds = true;
anView.CanShowCallout = false;
anView.Image = UIImage.FromFile("Icons/customMapPin.png");
return anView;
};
private void AddPin(UILongPressGestureRecognizer longTap, float value)
{
if (ifPointExist == false)
{
ifPointExist = true;
touchPoint = longTap.LocationInView(map);
pinMapCords = this.map.ConvertPoint(touchPoint, map);
CLLocation loc = new CLLocation(pinMapCords.Latitude, pinMapCords.Longitude);
map.AddAnnotations(new MKPointAnnotation()
{
Coordinate = new CLLocationCoordinate2D(pinMapCords.Latitude, pinMapCords.Longitude)
});
CLGeocoder geocoder = new CLGeocoder();
geocoder.ReverseGeocodeLocation(loc, (CLPlacemark[] placemarks, NSError error) =>
{
str = placemarks[0].AddressDictionary;
str.ToString();
});
AddCircle(value);
MKCoordinateSpan span = new MKCoordinateSpan(0.10, 0.10);
var coords = new CLLocationCoordinate2D(pinMapCords.Latitude, pinMapCords.Longitude);
map.Region = new MKCoordinateRegion(coords, span);
ifPointExist = false;
}
}
Thanks in advance

Related

Is there a way to add descriptive text beside each data point in BarChart BarChartSeries using OpenXML(C#) for PPT?

I am able to get the 0 as value. However I want to set a descriptive text like B does not have any data and similar is the case for D here in the chart.
I want to have text whenever a company does not have any value which is 0 in this case. This can happen for multiple companies so how can I automate this?
I am using this to put category data-Sample code
DocumentFormat.OpenXml.Drawing.Charts.CategoryAxisData categoryAxisData1 = new DocumentFormat.OpenXml.Drawing.Charts.CategoryAxisData();
C.StringReference stringReference2 = new C.StringReference();
C.Formula formula2 = new C.Formula
{
Text = "Sheet1!$A$2:$A$7"
};
C.StringCache stringCache2 = new C.StringCache();
C.PointCount pointCount2 = new C.PointCount() { Val = Convert.ToUInt32(companies.Count) };
stringCache2.Append(pointCount2);
int count = 0;
for (int i = companies.Count-1; i >= 0 ; i--)
{
C.StringPoint stringPoint = new C.StringPoint() { Index = Convert.ToUInt32(count) };
C.NumericValue numericValue = new C.NumericValue
{
Text = companies[i].CompanyName
};
stringPoint.Append(numericValue);
stringCache2.Append(stringPoint);
count++;
}
stringReference2.Append(formula2);
stringReference2.Append(stringCache2);
categoryAxisData1.Append(stringReference2);
Sample code for value on barchart-
C.Values values1 = new C.Values();
C.NumberReference numberReference1 = new C.NumberReference();
C.Formula formula3 = new C.Formula
{
Text = "Sheet1!$B$2:$B$7"
};
C.NumberingCache numberingCache1 = new C.NumberingCache();
C.FormatCode formatCode1 = new C.FormatCode
{
Text = "General"
};
numberingCache1.Append(formatCode1);
C.PointCount pointCount3 = new C.PointCount() { Val = Convert.ToUInt32(companies.Count) };
numberingCache1.Append(pointCount3);
for (int i = 0; i < companies.Count; i++)
{
C.NumericPoint numericPoint = new C.NumericPoint() { Index = Convert.ToUInt32(i) };
//C.NumericValue numericValue = new C.NumericValue
//{
// Text = (sliderValueForComapnies[i] > 0) ? sliderValueForComapnies[i].ToString() : "Data not avaialble",
//};
C.NumericValue numericValue = new C.NumericValue();
if (sliderValueForComapnies[i] > 0)
{
numericValue.Text = sliderValueForComapnies[i].ToString();
}
//else
//{
// this area will have the companies with 0 as value so what can I do here to add text?
//}
numericPoint.Append(numericValue);
numberingCache1.Append(numericPoint);
}
numberReference1.Append(formula3);
numberReference1.Append(numberingCache1);
values1.Append(numberReference1);

Place patterns on polyline in iOS using Xamarin.forms.maps

Im using xamarin.forms.maps and successfully getting the polyline but I want to get some patterns on it as here and not able to achieve it.
Can anyone please help me in solving this issue and my code is as below :
formsMap.DrawPolyLine = () =>
{
if (nativeMaps == null)
{
nativeMaps = Control as MKMapView;
}
nativeMaps.OverlayRenderer = GetOverlayRenderer;
CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[IOSMapViewModel.DeviceTrackData.Count];
int index = 0;
foreach (var position in IOSMapViewModel.DeviceTrackData)
{
coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
index++;
}
routeOverlay = MKGeodesicPolyline.FromCoordinates(coords);
if (nativeMap.Overlays != null)
nativeMaps.RemoveOverlays(nativeMap.Overlays);
IMKOverlay overlay = routeOverlay;
nativeMaps.AddOverlay(routeOverlay, MKOverlayLevel.AboveLabels);
};
nativeMap.GetViewForAnnotation = GetViewForAnnotation;
nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
}
}
MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlayWrapper)
{
if (polylineRenderer == null && !Equals(overlayWrapper, null))
{
var overlay = Runtime.GetNSObject(overlayWrapper.Handle) as IMKOverlay;
Foundation.NSNumber[] dashValues = { 3, 6 };
polylineRenderer = new MKPolylineRenderer(overlay as MKGeodesicPolyline)
{
FillColor = UIColor.Orange,
StrokeColor = UIColor.Orange,
LineWidth = 3,
Alpha = 1f,
LineDashPattern = dashValues
};
//polylineRenderer.CreatePath();
}
return polylineRenderer;
}

Radgridview visual issue

I have problem displaying the columns correctly,
some columns have some gap in between
I wanted to attach a picture but I need 10 reputation points to post image
See picture link below!!
Here is my code:
private void UpdateProducts()
{
MyPharmacyDataContext db = new MyPharmacyDataContext();
int tabid = Convert.ToInt32(radRibbonBar1.SelectedCommandTab.Name);
var list = from g in db.OutOfStocks
where g.ListID == tabid
select new { g.ID, g.Product.CName, g.Required, g.Product.Price, g.Product.Disscount, g.Product.BuyPrice, g.TotalBuy, Stock = g.Product.Available + "," + g.Product.AvailableMid + "," + g.Product.AvailableSmall,g.Product.Supplier.Title };
if (list.Count() > 0)
{
radGridView1.SummaryRowsBottom.Clear();
radGridView1.Columns.Clear();
radGridView1.Visible = true;
radGridView1.TableElement.TableHeaderHeight = 60;
GridViewTextBoxColumn num = new GridViewTextBoxColumn();
num.MaxWidth = 50;
num.Name = "num";
num.HeaderText = "م";
num.DataType = typeof(int);
radGridView1.Columns.Add(num);
radGridView1.DataSource = list;
radGridView1.Columns[1].IsVisible = false;
radGridView1.Columns[2].Width = 350;
radGridView1.Columns[2].HeaderText = "اسم المنتج";
radGridView1.Columns[2].Name = "Name";
radGridView1.Columns[2].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[3].MaxWidth = 60;
radGridView1.Columns[3].HeaderText = "عدد";
radGridView1.Columns[3].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[3].Name = "Q";
radGridView1.Columns[4].MaxWidth = 90;
radGridView1.Columns[4].HeaderText = "السعر";
radGridView1.Columns[4].Name = "Price";
radGridView1.Columns[4].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[4].FormatString = "{0:G29}";
radGridView1.Columns[5].MaxWidth = 80;
radGridView1.Columns[5].HeaderText = "الخصم";
radGridView1.Columns[5].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[5].FormatString = "{0:G29}";
radGridView1.Columns[6].MaxWidth = 100;
radGridView1.Columns[6].HeaderText = "سعر\nالشراء";
radGridView1.Columns[6].Name = "BuyPice";
radGridView1.Columns[6].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[6].FormatString = "{0:G29}";
radGridView1.Columns[7].MaxWidth = 100;
radGridView1.Columns[7].HeaderText = "اجمالي\nالشراء";
radGridView1.Columns[7].Name = "TotalBuyPice";
radGridView1.Columns[7].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[7].FormatString = "{0:G29}";
radGridView1.Columns[8].MaxWidth = 80;
radGridView1.Columns[8].MinWidth = 80;
radGridView1.Columns[8].Name = "Stock";
radGridView1.Columns[8].HeaderText = "الرصيد";
radGridView1.Columns[8].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[9].MaxWidth = 100;
radGridView1.Columns[9].MinWidth = 100;
radGridView1.Columns[9].Name = "Supplier";
radGridView1.Columns[9].HeaderText = "افضل\nمورد";
radGridView1.Columns[9].TextAlignment = ContentAlignment.MiddleCenter;
GridViewCheckBoxColumn checkbox = new GridViewCheckBoxColumn();
checkbox.MaxWidth = 30;
checkbox.HeaderText = "";
checkbox.DataType = typeof(bool);
checkbox.Name = "Ordered";
radGridView1.Columns.Add(checkbox);
var allpro = from g in db.OutOfStocks
where g.ListID == tabid
select g;
foreach (OutOfStock p in allpro)
{
foreach (GridViewRowInfo row in radGridView1.Rows)
{
if ((int)row.Cells[1].Value == p.ID)
{
if (p.Ordered == 'y')
row.Cells["Ordered"].Value = true;
else
row.Cells["Ordered"].Value = false;
}
}
}
GridViewSummaryItem total = new GridViewSummaryItem("Name", "الاجمالي", GridAggregateFunction.Avg);
GridViewSummaryItem price = new GridViewSummaryItem();
price.Name = "Price";
price.AggregateExpression = "(Sum(Q*Price))";
price.FormatString = "{0:G29}";
// GridViewSummaryItem price = new GridViewSummaryItem("Price", "{0}", GridAggregateFunction.Sum);
GridViewSummaryItem buypice = new GridViewSummaryItem("TotalBuyPice", "{0:G29}", GridAggregateFunction.Sum);
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem(new GridViewSummaryItem[] { total, price, buypice });
radGridView1.SummaryRowsBottom.Add(summaryRowItem);
radGridView1.Focus();
}
else
{
radGridView1.Visible = false;
}
if (radGridView1.Rows.Count() > 0)
radGridView1.ChildRows.Last().IsCurrent = true;
}
Here is the pic
https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpa1/v/t34.0-12/10893575_742987025776952_423788280_n.jpg?efg=eyJpIjoidCJ9&oh=c69f42a8f47d6529f2b9d89ab2782711&oe=54A71C8A&gda=1420210517_66e1b08ccf9c00fd3dcff31e1854b3cc

EPPlus how to change colors of PIE Chart in EXCEL

How to change the default colors of Excel Pie Chart using EPPlus programatically.
below is my code
var pieChart = worksheet.Drawings.AddChart("piechart", eChartType.Pie3D) as ExcelPieChart;
//Set top left corner to row 1 column 2
pieChart.SetPosition(18, 0, 0, 0);
pieChart.SetSize(350, 300);
pieChart.Series.Add(ExcelRange.GetAddress(12, 2, 15, 2),ExcelRange.GetAddress(12, 1, 15, 1) );
pieChart.Legend.Position = eLegendPosition.Bottom;
pieChart.Legend.Border.Fill.Color = Color.Green;
pieChart.Legend.Border.LineStyle = eLineStyle.Solid;
pieChart.Legend.Border.Fill.Style = eFillStyle.SolidFill;
pieChart.Title.Text = "Current Status";
pieChart.DataLabel.ShowCategory = false;
pieChart.DataLabel.ShowPercent = true;
I want to change the default colors to the some bright colors.
Suggest and throw some light on this.
Inspired by Ernie's answer, here is an extension method that works for setting the color and thickness of a line chart series, and a non tested version for setting the color of a pie chart data point:
public static void SetSeriesStyle(this ExcelLineChart chart, ExcelChartSerie series, Color color, decimal? thickness = null) {
if (thickness < 0) throw new ArgumentOutOfRangeException("thickness");
var i = 0;
var found = false;
foreach (var s in chart.Series) {
if (s == series) {
found = true;
break;
}
++i;
}
if (!found) throw new InvalidOperationException("series not found.");
//Get the nodes
var nsm = chart.WorkSheet.Drawings.NameSpaceManager;
var nschart = nsm.LookupNamespace("c");
var nsa = nsm.LookupNamespace("a");
var node = chart.ChartXml.SelectSingleNode(#"c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser[c:idx[#val='" + i.ToString(CultureInfo.InvariantCulture) + "']]", nsm);
var doc = chart.ChartXml;
//Add the solid fill node
var spPr = doc.CreateElement("c:spPr", nschart);
var ln = spPr.AppendChild(doc.CreateElement("a:ln", nsa));
if (thickness.HasValue) {
var w = ln.Attributes.Append(doc.CreateAttribute("w"));
w.Value = Math.Round(thickness.Value * 12700).ToString(CultureInfo.InvariantCulture);
var cap = ln.Attributes.Append(doc.CreateAttribute("cap"));
cap.Value = "rnd";
}
var solidFill = ln.AppendChild(doc.CreateElement("a:solidFill", nsa));
var srgbClr = solidFill.AppendChild(doc.CreateElement("a:srgbClr", nsa));
var valattrib = srgbClr.Attributes.Append(doc.CreateAttribute("val"));
//Set the color
valattrib.Value = color.ToHex().Substring(1);
node.AppendChild(spPr);
}
public static void SetDataPointStyle(this ExcelPieChart chart, int dataPointIndex, Color color) {
//Get the nodes
var nsm = chart.WorkSheet.Drawings.NameSpaceManager;
var nschart = nsm.LookupNamespace("c");
var nsa = nsm.LookupNamespace("a");
var node = chart.ChartXml.SelectSingleNode("c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser", nsm);
var doc = chart.ChartXml;
//Add the node
//Create the data point node
var dPt = doc.CreateElement("c:dPt", nschart);
var idx = dPt.AppendChild(doc.CreateElement("c:idx", nschart));
var valattrib = idx.Attributes.Append(doc.CreateAttribute("val"));
valattrib.Value = dataPointIndex.ToString(CultureInfo.InvariantCulture);
node.AppendChild(dPt);
//Add the solid fill node
var spPr = doc.CreateElement("c:spPr", nschart);
var solidFill = spPr.AppendChild(doc.CreateElement("a:solidFill", nsa));
var srgbClr = solidFill.AppendChild(doc.CreateElement("a:srgbClr", nsa));
valattrib = srgbClr.Attributes.Append(doc.CreateAttribute("val"));
//Set the color
valattrib.Value = color.ToHex().Substring(1);
dPt.AppendChild(spPr);
}
public static String ToHex(this Color c) {
return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
}
Usage:
lineChart.SetSeriesStyle(s, color: Color.FromArgb(0, 0, 0), thickness: 6m);
pieChart.SetDataPointStyle(dataPointIndex: 0, color: Color.FromArgb(0, 0, 0));
Just thought I would give back a little as I ran into a similar problem. Short answer is EEPlus does not support the ability to change the colors of the individual slices so I had to rely on xml manipulation. Not pretty and requires good knowledge of the data you are outputting - you need to know the number of slices you are expecting. But it works and this should be applicable to other pie chart types besides 3D.
Here is a test method that demonstrates. Did this against EPP 4.0.1 but should work just as well with prior versions:
[TestMethod]
public void Change_3DPieChart_Color()
{
const string PIE_PATH = "c:chartSpace/c:chart/c:plotArea/c:pie3DChart/c:ser";
var existingFile = new FileInfo(#"c:\temp\temp.xlsx");
if (existingFile.Exists)
existingFile.Delete();
using (var package = new ExcelPackage(existingFile))
{
var workbook = package.Workbook;
var worksheet = workbook.Worksheets.Add("newsheet");
//Some data
worksheet.Cells["A12"].Value = "wer";
worksheet.Cells["A13"].Value = "sdf";
worksheet.Cells["A14"].Value = "wer";
worksheet.Cells["A15"].Value = "ghgh";
worksheet.Cells["B12"].Value = 53;
worksheet.Cells["B13"].Value = 36;
worksheet.Cells["B14"].Value = 43;
worksheet.Cells["B15"].Value = 86;
//Create the pie
var pieChart = (ExcelPieChart) worksheet.Drawings.AddChart("piechart", eChartType.Pie3D);
//Set top left corner to row 1 column 2
pieChart.SetPosition(18, 0, 0, 0);
pieChart.SetSize(350, 300);
pieChart.Series.Add(ExcelCellBase.GetAddress(12, 2, 15, 2), ExcelCellBase.GetAddress(12, 1, 15, 1));
pieChart.Legend.Position = eLegendPosition.Bottom;
pieChart.Legend.Border.Fill.Color = Color.Green;
pieChart.Legend.Border.LineStyle = eLineStyle.Solid;
pieChart.Legend.Border.Fill.Style = eFillStyle.SolidFill;
pieChart.Title.Text = "Current Status";
pieChart.DataLabel.ShowCategory = false;
pieChart.DataLabel.ShowPercent = true;
//Get the nodes
var ws = pieChart.WorkSheet;
var nsm = ws.Drawings.NameSpaceManager;
var nschart = nsm.LookupNamespace("c");
var nsa = nsm.LookupNamespace("a");
var node = pieChart.ChartXml.SelectSingleNode(PIE_PATH, nsm);
var doc = pieChart.ChartXml;
//Add the node
var rand = new Random();
for (var i = 0; i < 4; i++)
{
//Create the data point node
var dPt = doc.CreateElement("dPt", nschart);
var idx = dPt.AppendChild(doc.CreateElement("idx", nschart));
var valattrib = idx.Attributes.Append(doc.CreateAttribute("val"));
valattrib.Value = i.ToString(CultureInfo.InvariantCulture);
node.AppendChild(dPt);
//Add the solid fill node
var spPr = doc.CreateElement("spPr", nschart);
var solidFill = spPr.AppendChild(doc.CreateElement("solidFill", nsa));
var srgbClr = solidFill.AppendChild(doc.CreateElement("srgbClr", nsa));
valattrib = srgbClr.Attributes.Append(doc.CreateAttribute("val"));
//Set the color
var color = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));
valattrib.Value = ColorTranslator.ToHtml(color).Replace("#", String.Empty);
dPt.AppendChild(spPr);
}
package.Save();
}
}

Creating multiple chart in c#

for (int i = 0; i < 5; i += 1)
{
ShowReports(0);
}
private void ShowReports(int ComboID)
{
Graph.Series["Series1"].ChartType = SeriesChartType.Line;
Graph.Series["Series1"].BorderWidth = 2;
Graph.Series["Series1"].MarkerStyle = MarkerStyle.Circle;
Graph.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "dd-MMM-yyy";
Graph.ChartAreas["ChartArea1"].AxisX.Title = "Date";
Graph.ChartAreas["ChartArea1"].AxisY.Title = "Average Score (%) ";
Graph.ChartAreas["ChartArea1"].AxisY.Minimum = 0;
Graph.ChartAreas["ChartArea1"].AxisY.Maximum = 100;
Graph.ChartAreas["ChartArea1"].AxisY.Interval = 10;
Graph.Series["Series1"].ToolTip = "Date :#VALX Avg Score(%) :#VALY";
Graph.Titles.Add(dtReportDetails.Rows[0].ItemArray[1].ToString());
Graph.Titles.Add(SetGraphTitile());
Graph.Titles[0].Font = new System.Drawing.Font("Arial", 20);
Graph.Titles[0].ForeColor = System.Drawing.Color.Black;
Graph.Titles[1].Font = new System.Drawing.Font("Arial", 13);
Graph.Titles[1].ForeColor = System.Drawing.Color.Black;
Graph.Titles[1].Visible = false;
// Graph.Series[0].Points.AddXY(DateTime.Parse(dtReportDetails.Rows[0].ItemArray[4].ToString()), dtReportDetails.Rows[0].ItemArray[5].ToString());
Graph.Series[0].XValueMember = dtReportDetails.Rows[0].ItemArray[4].ToString();
Graph.Series[0].YValueMembers = dtReportDetails.Rows[0].ItemArray[5].ToString();
Graph.Series[0].MarkerStyle = MarkerStyle.Circle;
Graph.Legends.Add("Legend1");
Graph.Legends[0].Enabled = false;
Graph.Legends[0].Docking = Docking.Bottom;
Graph.Legends[0].Alignment = System.Drawing.StringAlignment.Center;
Graph.DataSource = dv;
Graph.DataBind();
}
else if (dtReportDetails.Rows[0].ItemArray[7].ToString() == "Bar")
{
Graph.Series["Series1"].ChartType = SeriesChartType.Column;
Graph.Series["Series1"].BorderWidth = 2;
//Graph.Series["Series1"].MarkerStyle = MarkerStyle.Circle;
//Graph.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "dd-MMM-yyy";
//Graph.ChartAreas["ChartArea1"].AxisX.Title = "Date";
//Graph.ChartAreas["ChartArea1"].AxisY.Title = "Average Score (%) ";
Graph.Series["Series1"].ToolTip = "(#VALX,#VALY)";
Graph.Titles.Add(dtReportDetails.Rows[0].ItemArray[1].ToString());
Graph.Titles.Add(SetGraphTitile());
Graph.Titles[0].Font = new System.Drawing.Font("Arial", 20);
Graph.Titles[0].ForeColor = System.Drawing.Color.Black;
Graph.Titles[1].Font = new System.Drawing.Font("Arial", 13);
Graph.Titles[1].ForeColor = System.Drawing.Color.Black;
Graph.Titles[1].Visible = false;
Graph.ChartAreas["ChartArea1"].AxisX.Title = "Learning Domains";
Graph.ChartAreas["ChartArea1"].AxisY.Title = "Covered";
// Graph.Series[0].Points.AddXY(DateTime.Parse(dtReportDetails.Rows[0].ItemArray[4].ToString()), dtReportDetails.Rows[0].ItemArray[5].ToString());
Graph.Series[0].XValueMember = dtReportDetails.Rows[0].ItemArray[4].ToString();
Graph.Series[0].YValueMembers = dtReportDetails.Rows[0].ItemArray[5].ToString();
// Graph.Series[0].MarkerStyle = MarkerStyle.Circle;
Graph.Legends.Add("Legend1");
Graph.Legends[0].Enabled = false;
Graph.Legends[0].Docking = Docking.Bottom;
Graph.Legends[0].Alignment = System.Drawing.StringAlignment.Center;
Graph.DataSource = dv;
Graph.DataBind();
Random random = new Random();
foreach (var item in Graph.Series[0].Points)
{
System.Drawing.Color c = System.Drawing.Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
item.Color = c;
}
Graph.Series[0]["PointWidth"] = "0.2";
Graph.Series[0]["BarLabelStyle"] = "Center";
Graph.Series[0]["PixelPointDepth"] = "99";
Graph.Series[0]["DrawingStyle"] = "Cylinder";
}
This is my code for creating graph,for creating 1 graph i have no problem ,but creating more than one i will get error:A chart element with the name 'Legend1' already exists in the 'LegendCollection'.because i am creating same legends each time.So can you help to get rid of this problem.
Getting around the issue of the legend object name should be as simple as setting it via a string that takes your ComboID parameter into account.
string myLegendTitle = "Legend" + ComboID;
Graph.Legends.Add(myLegendTitle);
In order to create multiple charts - on the assumption you're using Microsoft Chart controls would look something like
for (int i = 0; i < 5; i += 1)
{
ShowReports(0);
}
private void ShowReports(int ComboID)
{
var myNewGraph = new System.Windows.Forms.DataVisualization.Charting.Chart();
myNewGraph .Series["Series1"].ChartType = SeriesChartType.Line;
myNewGraph .Series["Series1"].BorderWidth = 2;
myParentControl.Controls.Add(myNewGraph);
}
The key points being to instantiate a new Chart in your ShowReports method, then set all the properties specifically as before BUT on the new graph / chart object. Then ensure you add the control to the appropriate container if it's not already there.
If you know you will have, for example, 5 charts, then another approach is to build them at design time instead, and use a switch approach to set your variable, eg.
private void ShowReports(int ComboID)
{
Chart myNewGraph;
switch (ComboID)
{
case 1:
myNewGraph = Graph1;
break;
}
myNewGraph .Series["Series1"].ChartType = SeriesChartType.Line;
myNewGraph .Series["Series1"].BorderWidth = 2;
}
Is the code for create 5 graphs..
for(int i=0;i< 6;i++)
{
Chart1.Series.Add("Series1" + t.ToString());
Chart1.ChartAreas.Add("ChartArea1" + t.ToString());
Chart1.Legends.Add("Legend1" + t.ToString());
Chart1.Series[t].ChartArea = "ChartArea1" + t.ToString();
Chart1.Series[t].ChartType = SeriesChartType.Column;
Chart1.Series[t].BorderWidth = 2;
Chart1.Series[t].ToolTip = "(#VALX,#VALY)";
Chart1.ChartAreas["ChartArea1" + t.ToString()].AxisX.Title = "Learning Domains";
Chart1.ChartAreas["ChartArea1" + t.ToString()].AxisY.Title = "Covered";
}

Categories

Resources