for (int t = 0; t < ARF.Rows.Count; t += 1)
{
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";
Chart1.Legends.Add("Legend1" + t.ToString());
Chart1.Legends["Legend1" + t.ToString()].Enabled = false;
// Chart1.Legends["Legend1" + t.ToString()].Docking = Docking.Bottom;
Chart1.Legends["Legend1" + t.ToString()].Alignment = System.Drawing.StringAlignment.Center;
Chart1.Legends["Legend1" + t.ToString()].DockedToChartArea = "ChartArea1" + t.ToString();
// Chart1.Legends["Legend1" + t.ToString()].IsDockedInsideChartArea = false;
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;
}
Chart1.Series[t]["PointWidth"] = "0.2";
Chart1.Series[t]["BarLabelStyle"] = "Center";
Chart1.Series[t]["PixelPointDepth"] = "99";
Chart1.Series[t]["DrawingStyle"] = "Cylinder";
}
for (int i = 0; i < 5; i++)
{
GridView gv = new GridView();
gv.DataSource = ds;
ph.Controls.Add(gv);
}
This is code to creating 5 charts, i want 5 charts with 5 tables of Grid View data together in 1 shot. can you please help me to do...i have tried but graphs are coming and grids are not visible.
If your using web application you can use google chart:
You can refer this link:
https://developers.google.com/chart/interactive/docs/gallery/controls
Related
I'm generating an excel using the following code in my ASP.Net MVC Application
var fileName = DateTime.Now.ToString("yyyy-MM-dd--hh-mm-ss") + ".xlsx";
var outputDir = ConfigurationManager.AppSettings["ExcelUploadPath"];
// var fileName = "ExcellData.xlsx";
var file = new FileInfo(outputDir + fileName);
var fDate = JsonConvert.DeserializeObject<DateTime>(fromDate);
var tDate = JsonConvert.DeserializeObject<DateTime>(toDate);
using (var package = new OfficeOpenXml.ExcelPackage(file))
{
// add a new worksheet to the empty workbook
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Plan " + DateTime.Now.ToShortDateString());
// --------- Data and styling goes here -------------- //
DataTable dt = planService.GetFlow(fDate, tDate, customerId, ordertypeId, suppliers, items);
if (dt != null)
{
int iCol = 1;
// Add column headings...
for (int i = 9; i < dt.Columns.Count; i++)
{
dt.Columns[i].ColumnName = dt.Columns[i].ColumnName.MultiInsert("/", 1, 3);
}
foreach (DataColumn c in dt.Columns)
{
worksheet.Cells[1, iCol].Value = c.ColumnName;
worksheet.Cells[1, iCol].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[1, iCol].Style.Font.Bold = true;
worksheet.Cells[1, iCol].Style.Fill.BackgroundColor.SetColor(Color.LightGray);
iCol++;
}
for (int j = 0; j < dt.Rows.Count; j++)
{
for (int k = 0; k < dt.Columns.Count; k++)
{
worksheet.Cells[j + 2, k + 1].Value = dt.Rows[j].ItemArray[k].ToString();
if (int.Parse(dt.Rows[j].ItemArray[7].ToString()) == 6)
{
worksheet.Cells[j + 2, k + 1].Style.Locked = false;
worksheet.Cells[j + 2, k + 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[j + 2, k + 1].Style.Fill.BackgroundColor.SetColor(Color.Cyan);
}
if (int.Parse(dt.Rows[j].ItemArray[7].ToString()) == 7)
{
worksheet.Cells[j + 2, k + 1].Style.Locked = false;
worksheet.Cells[j + 2, k + 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[j + 2, k + 1].Style.Fill.BackgroundColor.SetColor(Color.Magenta);
//worksheet.Cells[j + 2, k + 1].Formula =
if((k+1) > 10){
var addressList = new List<string>();
for (int i = 11; i <= k+1; i++)
{
addressList.Add(worksheet.Cells[((j + 2) -1) , i].Address);
}
var lstAdress = String.Join(",", addressList);
worksheet.Cells[j + 2, k + 1].Formula = "SUM(" + lstAdress + ")";
}
}
if (int.Parse(dt.Rows[j].ItemArray[7].ToString()) == 8)
{
//worksheet.Cells[j + 2, k + 1].Style.Locked = false;
worksheet.Cells[j + 2, k + 1].Style.Fill.PatternType = ExcelFillStyle.Solid;
worksheet.Cells[j + 2, k + 1].Style.Fill.BackgroundColor.SetColor(Color.Gray);
}
}
var colCount = dt.Columns.Count;
// worksheet.Cells[j+2, 8, j+2, colCount- 1].Style.Numberformat.Format = "0.000";
var range = worksheet.Cells[j + 2, 9, j + 2, colCount - 1];
var r = range.ToString();
var decimalValidation = worksheet.DataValidations.AddDecimalValidation(range.ToString());
decimalValidation.ShowErrorMessage = true;
decimalValidation.ErrorStyle = ExcelDataValidationWarningStyle.stop;
decimalValidation.ErrorTitle = "The value you entered is not valid";
decimalValidation.Error = "This cell must be a valid positive number.";
decimalValidation.Operator = ExcelDataValidationOperator.greaterThanOrEqual;
decimalValidation.Formula.Value = 0D;
}
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
worksheet.Column(1).Hidden = true;
worksheet.Column(2).Hidden = true;
worksheet.Column(3).Hidden = true;
worksheet.Column(4).Hidden = true;
worksheet.Column(5).Hidden = true;
worksheet.Column(8).Hidden = true;
worksheet.Column(9).Hidden = true;
worksheet.Column(10).Hidden = true;
worksheet.Protection.IsProtected = true;
// save our new workbook and we are done!
worksheet.Calculate();
package.Save();
return Json(fileName, JsonRequestBehavior.AllowGet);
}
else
{
return Json("NoData", JsonRequestBehavior.AllowGet);
}
}
return Json("", JsonRequestBehavior.AllowGet);
Here I'm setting my formula with comma separated cell names eg:
SUM(A1,A2,A3.. etc)
The excel file is generating correctly. But the problem is the formula calculation is not happen when I open my excel file.
The formula works when I manually change a cell value in Column Type Agreed Flow.
And it can only identify values of manually edited cells.
How can I resolve this?
Formula recalculation is both an Excel and a workbook setting.
You could set it with at the workbook level with
workbook.CalcMode = ExcelCalcMode.Automatic;
If the user has set it to manual though, the formulas won't be recalculated.
If you want to ensure the saved values are correct you can force the calculation by calling
worksheet.Calculate();
You can also calculate the formulas at the workbook or range level, eg :
worksheet.Cells[j + 2, k + 1].Calculate();
or
package.Workbook.Calculate();
This is explained in the documentation. Keep in mind that EPPlus doesn't contain Excel's formula engine. It uses its own engine to parse and calculate formulas. Some things aren't supported
It worked when I change my formula as follows..
var addressList = new List<string>();
for (int i = 11; i <= k+1; i++)
{
addressList.Add(worksheet.Cells[((j + 2) -1) , i].Address);
}
var lstAdress = String.Join("+", addressList);
worksheet.Cells[j + 2, k + 1].Formula = "(" + lstAdress + ")";
I think there is an issue in my excel sheet when I use the SUM function So I write the formula without using it. Then it worked
(A1+B1+C1+D1+ ..... etc)
I am using the Itextsharp PDF tool to generate PDF using asp.net and C# , In that in one PDFPtable the last row data is repeating on next page means part of a table forwarded to next page. so want to show header for that Table on next page.
This is my code.
Document doc = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 20, 10);
string pdfFilePath = Server.MapPath(".") + "/pdf/myPdf" + Guid.NewGuid().ToString("N") + ".pdf";
try
{
//Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
FileStream fs = new FileStream(pdfFilePath, FileMode.Create);
//
PdfWriter wri = PdfWriter.GetInstance(doc, fs);
//Header Section
string strImagePath = Server.MapPath("Images");
string strReportName = oReportDTO.strReportName + " " + oReportDTO.oDateRange.FromDate.ToString(DateFormat);
Chunk headerchunk = new Chunk(strReportName, new Font(1, 8.0f));
HeaderFooter oHeader = new HeaderFooter(new Phrase(headerchunk), false);
oHeader.Border = Rectangle.NO_BORDER;
oHeader.Alignment = 1;
doc.Header = oHeader;
//Footer Section
string name ="Logged in as : " +currentLoggedInUser.UserName + new string(' ',70)+ "Page Number : " + doc.PageNumber;
Chunk Footerchunk1 = new Chunk(name, new Font(1, 5.0f));
HeaderFooter oFooter1 = new HeaderFooter(new Phrase(Footerchunk1), true);
oFooter1.Border = Rectangle.NO_BORDER;
oFooter1.Alignment = 1;
doc.Footer = oFooter1;
iTextSharp.text.Image imgFooter = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromFile(strImagePath + "/TransRisk Logo168x97.png"), System.Drawing.Imaging.ImageFormat.Jpeg);
imgFooter.ScaleAbsolute(80, 50);
Chunk footerchunk = new Chunk(imgFooter, 260.0f, 0.0f);
HeaderFooter oFooter = new HeaderFooter(new Phrase(name),new Phrase(footerchunk));
oFooter.Border =Rectangle.NO_BORDER;
doc.Footer = oFooter;
doc.Open();//Open Document to write
Font font8 = FontFactory.GetFont("ARIAL", 7);
HtmlTable dt = customMatrixReport;
if (dt.Rows.Count > 0)
{
//Craete instance of the pdf table and set the number of column in that table
int startColumnPosition = 1;
int endColumnPosition = 13;//End Column number in Pdf Page
int NoOfReports = Convert.ToInt32(Math.Ceiling((decimal)(dt.Rows[0].Cells.Count - 1) / endColumnPosition));//Count How many Pages to show
int pageRowCount = 0;
List<PdfPCell> lstHeaderCells = new List<PdfPCell>();
PdfPTable oPdfTable = null;
PdfPCell oPdfPCell = null;
for (int report = 1; report <= NoOfReports; ++report)
{
doc.Add(oHeader);
//ColumnText.ShowTextAligned(
int noOfColumns = -1;
if (endColumnPosition > dt.Rows[0].Cells.Count - 1) { endColumnPosition = dt.Rows[0].Cells.Count - 1; noOfColumns = (endColumnPosition - startColumnPosition) + 2; oPdfTable = new PdfPTable(noOfColumns); }
else
{
oPdfTable = new PdfPTable(14);
//Widths Count
noOfColumns = 14;
}
oPdfTable.TotalWidth = 650f;
List<float> lstwidths = new List<float>();
lstwidths.Add(100f);
for (int i = 2; i <= noOfColumns; ++i)
{
lstwidths.Add(80f);
}
oPdfTable.SetTotalWidth(lstwidths.ToArray());
pageRowCount = 0;
for (int rows = 0; rows < dt.Rows.Count; rows++)
{
//PageRowCount
pageRowCount = pageRowCount + 1;
//Description celll
if (rows == 0 )
{
//Background color for table header
oPdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows].Cells[0].InnerText, new Font(1, 8.0f, 1, Color.WHITE))));
oPdfPCell.BackgroundColor = new Color(118, 147, 199);
oPdfTable.AddCell(oPdfPCell);
}
else
{
//background color for Table cells
oPdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows].Cells[0].InnerText,new Font(1, 8.0f))));
oPdfPCell.BackgroundColor = new Color(232, 237, 255);
oPdfTable.AddCell(oPdfPCell);
}
//for header cel
if (rows == 0)
{
lstHeaderCells.Add(oPdfPCell);
}
for (int column = startColumnPosition; column <= endColumnPosition; column++)
{
if (rows == 0)
{
oPdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows].Cells[column].InnerText, new Font(1, 8.0f, 1, Color.WHITE))));
oPdfPCell.BackgroundColor = new Color(118, 147, 199);
oPdfTable.AddCell(oPdfPCell);
}
else
{
oPdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows].Cells[column].InnerText, new Font(1, 8.0f))));
oPdfPCell.BackgroundColor = new Color(232, 237, 255);
oPdfPCell.Column.Alignment = 2;
oPdfTable.AddCell(oPdfPCell);
}
if (rows == 0)
{
lstHeaderCells.Add(oPdfPCell);
}
}
if (pageRowCount >= 40 && rows != (dt.Rows.Count - 1))
{
pageRowCount = 0; doc.Add(oPdfTable); doc.NewPage(); doc.Add(oHeader); oPdfTable = new PdfPTable(noOfColumns); oPdfTable.SetTotalWidth(lstwidths.ToArray()); foreach (PdfPCell oHeaderCell in lstHeaderCells) { oPdfTable.AddCell(oHeaderCell); }
}
}
startColumnPosition = endColumnPosition + 1;
endColumnPosition = endColumnPosition + 13;
oPdfTable.SpacingBefore = 10;
oPdfTable.SpacingAfter = 10;
doc.Add(oPdfTable);
//doc.NewPage();
}
}
else
doc.Add(oHeader);
}
finally
{
doc.Close();
}
help me..
Change this line-
if (endColumnPosition > dt.Rows[0].Cells.Count - 1) { endColumnPosition = dt.Rows[0].Cells.Count - 1; noOfColumns = (endColumnPosition - startColumnPosition) + 2; oPdfTable = new PdfPTable(noOfColumns); }
To this-
if (endColumnPosition > dt.Rows[0].Cells.Count - 1) { endColumnPosition = dt.Rows[0].Cells.Count - 1; noOfColumns = (endColumnPosition - startColumnPosition) + 2; oPdfTable = new PdfPTable(noOfColumns); oPdfTable.HeaderRows = 1;}
After this line-
oPdfTable = new PdfPTable(14);
Add this-
oPdfTable.HeaderRows = 1;
Change this line-
pageRowCount = 0; doc.Add(oPdfTable); doc.NewPage(); doc.Add(oHeader); oPdfTable = new PdfPTable(noOfColumns); oPdfTable.SetTotalWidth(lstwidths.ToArray()); foreach (PdfPCell oHeaderCell in lstHeaderCells) { oPdfTable.AddCell(oHeaderCell); }
To this-
pageRowCount = 0; doc.Add(oPdfTable); doc.NewPage(); doc.Add(oHeader); oPdfTable = new PdfPTable(noOfColumns); oPdfTable.HeaderRows = 1; oPdfTable.SetTotalWidth(lstwidths.ToArray()); foreach (PdfPCell oHeaderCell in lstHeaderCells) { oPdfTable.AddCell(oHeaderCell); }
I have a list of group box controls and i need to display only few questions in the flow layout panel but it is not displaying properly(width and height reduced) but if I add that controls to the form it is displaying properly
here is my code. please help me how to get back from this problem
code of flow layout panel(displyQues)
private void getQuestions(int quesid)
{
int j = 1;
for (int i = quesid; i <= lstgrpques.Count; i++)
{
displyQues.Location = new Point(15, 30);
displyQues.Show();
displyQues.Size = new System.Drawing.Size(1218, 620);
displyQues.AutoScroll = true;
lstgrpques[i - 1].Show();
displyQues.WrapContents = false;
displyQues.Controls.Add(lstgrpques[i - 1]);
displyQues.FlowDirection = FlowDirection.TopDown;
qstnId++;
j++;
if (j == 5)
{
break;
}
}
}
code of group box
foreach (var question in questions)
{
int QustTxtHght = 0;
GroupBox QuesAnsoptn = new GroupBox();
QuesAnsoptn.Hide();
QuesAnsoptn.AutoSize = true;
QuesAnsoptn.Width = 820;
QuesAnsoptn.Location = new Point(15, QustHgt);
var quest = question.Attribute("ques").Value.Trim();
if (quest.Contains('{'))
{
quest = GetFormatCode(quest);
QustTxtHght = quest.Length +40;
}
else
QustTxtHght = 15;
QuesAnsoptn.Text = question.Attribute("id").Value + ". " + quest;
QuesAnsoptn.Font = new Font("Microsoft Sans Serif", 10);
var options = question.Descendants("option");
var optHgt = 0;
foreach (var option in options)
{
RadioButton rdbtn = new RadioButton();
rdbtn.AutoSize = true;
rdbtn.Location = new Point(20, QustTxtHght + optHgt + 10);
rdbtn.Name = k.ToString();
lstRdOptns.Add(rdbtn);
rdbtn.Font = new Font("Microsoft Sans Serif", 10);
var opt = option.Value;
var loc = 0;
if (opt.Contains('{'))
{
opt = GetFormatCode(opt);
loc = opt.Length + 40;
}
else { loc = rdbtn.Size.Height; }
rdbtn.Text = opt;
optHgt = loc + optHgt;
QuesAnsoptn.Controls.Add(rdbtn);
}
k++;
this.Controls.Add(QuesAnsoptn);
QustHgt = QuesAnsoptn.Size.Height + QustHgt + 20;
QuesAnsoptn.Size = new System.Drawing.Size(820,QuesAnsoptn.Size.Height);
lstgrpques.Add(QuesAnsoptn);
}
I am trying to add controls at run-time for a Windows Phone app but I can't add more than 2 controls to the canvas. I have a textbox in mainscreen, and the user will enter a number which will yield that many textboxes. This code works for 0, 1, or 2 textboxes, but cannot add more than 2:
`int seriuzunlugu;
seriuzunlugu=Convert.ToInt32(SeriUzunluguTxt.Text);
int Xtop, Xleft, Ytop, Yleft;
Xtop = 10;
Xleft = 70;
Ytop = 10;
Yleft = 250;
for (int i = 0; i <seriuzunlugu ; i++)
{
//Xi değeri
TextBox Xi = new TextBox();
Xi.Name = "X" + i.ToString();
Xi.Width = 5;
Xi.Height = 5;
canvas.Children.Add(Xi);
Canvas.SetLeft(Xi,Xleft);
Canvas.SetTop(Xi,Xtop);
Xtop = +60;
//Yi değeri
TextBox Yi = new TextBox();
Yi.Name = "Y" + i.ToString();
Yi.Width = 5;
Yi.Height = 5;
canvas.Children.Add(Yi);
Canvas.SetLeft(Yi, Yleft);
Canvas.SetTop(Yi, Ytop);
Ytop = +60;
}
//X değeri
TextBox x = new TextBox();
x.Name = "xdegeri";
x.Width = 50;
x.Height = 10;
x.Text = canvas.Children.Count.ToString();
canvas.Children.Add(x);
Canvas.SetTop(x, Xtop + 50);
Canvas.SetLeft(x, Xleft);`
I try to add multiple curves and yaxises using ZedGraph. But I added points to the first curve succesfully after I tried to add the second curve. The first one values' disappear and
myCurve.Points.Count equals 0. For example, if I add 6 curves, only the sixth one has values others count =0. Also any of them show up on the graph. Here is the code:
colors = new Color[ff.documentColumnCount + 4];
zedGraphControl1.IsShowPointValues = true;
myPane = zedGraphControl1.GraphPane;
LineItem myCurve;
Color[] colors;
myPane.XAxis.Type = ZedGraph.AxisType.Date;
myPane.XAxis.Scale.Format = "HH:mm:ss";
myPane.XAxis.Scale.MajorUnit = DateUnit.Second;
zamanValue = new double[ff.tarihSaat.Length - 4]; // x axis time values. ff is another windows form name, no problem here.
for (int i = 0; i < ff.tarihSaat.Length - 4; i++)
{
zamanValue[i] = (double)new XDate(ff.tarihSaat[i].Year,
ff.tarihSaat[i].Month,
ff.tarihSaat[i].Day,
ff.tarihSaat[i].Hour,
ff.tarihSaat[i].Minute,
ff.tarihSaat[i].Second);
counter++;
}
yaxisArray = new YAxis[ff.documentColumnCount + 4]; // temp y axises
for (int k = 0; k < chckboxNumber; k++)
{
tempPointPairList.Clear();
tempPointPairList = createPairPointList(k); // Creates points, I see the correct values everytime, also no problem here.
minYvalues[k] = Findmin(tempPointPairList);
maxYvalues[k] = FindMax(tempPointPairList);
myCurve = myPane.AddCurve(ff.columnNames[k + 3], tempPointPairList, colors[k], SymbolType.None);
myCurve.Line.Width = 2.5f;
//myCurve.IsVisible = true;
myCurve.YAxisIndex = k;
myCurve.IsVisible = true;
if (k == 0)
{
myPane.YAxis.IsVisible = true;
myPane.YAxis.Scale.Max = 1;
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.MajorStep = (myPane.YAxis.Scale.Max - myPane.YAxis.Scale.Min) / 10;
myPane.YAxis.MajorGrid.IsVisible = true;
}
else
{
yaxisArray[k] = new YAxis(ff.columnNames[k + 3]);
//yaxisArray[k].Color = colors[k];
yaxisArray[k].IsVisible = false;
yaxisArray[k].Title.IsVisible = false;
myPane.YAxisList.Add(yaxisArray[k]);
if (minYvalues[k] == maxYvalues[k])
{
yaxisArray[k].Scale.Min = minYvalues[k] - 0.1;
yaxisArray[k].Scale.Max = maxYvalues[k] + 0.1;
}
else
{
yaxisArray[k].Scale.Min = minYvalues[k];
yaxisArray[k].Scale.Max = maxYvalues[k];
}
myPane.YAxisList.Add(yaxisArray[k]);
}
yAxisListIndexes[k] = myPane.YAxisList.Count-1;
minTextBoxes[k].Text = minYvalues[k].ToString();
maxTextBoxes[k].Text = maxYvalues[k].ToString();
durum[k].previousState = 1;
durum[k].currentState = 1;
chckBoxList[k].Checked = true;
myCurve.Clear();
}
myPane.XAxis.Scale.Min = zamanValue[0];
myPane.XAxis.Scale.Max = zamanValue[zamanValue.Length - 1];
//myPane.YAxisList[0].IsVisible = true;
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();
zedGraphControl1.Refresh();
Where is the mistake?
You don't add curves to each other, you add them to myPane.CurveList so you have them in myPane.CurveList[0], myPane.CurveList[1] and so on, not in myCurve. myCurve serves as store for current curve you are working with. When you call
myCurve = myPane.AddCurve(ff.columnNames[k + 3], tempPointPairList, colors[k], SymbolType.None);
a brand new curve is created, added to myPane.CurveList and is written into myCurve variable. It has a fresh state as it's just created. You can access your previous curve(s) in myPane.CurveList.