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);
}
Related
For last 2 days I stuck with a line chart issue with EPPlus. My objective is to create a line chart with EPPlus and line style will be dash line like below image. picture attached.
I search a lot Google for 2 days still got no relevant hint to have dash line in chart. I am not sure that at all EPPlus support dash line. I am using EPPlus version 6.0 and .NET Framework version 4.8. This is a sample code which generate chart in excel sheet with one line but I need that line will be dash line. please someone see my code and tell me what is missing in my code for which I could not have dash line style of line chart.
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
var newFile = new FileInfo(filepath);
using (ExcelPackage xlPackage = new ExcelPackage(newFile))
{
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("test");
worksheet.Cells["A1"].Value = 1;
worksheet.Cells["A2"].Value = 2;
worksheet.Cells["A3"].Value = 3;
worksheet.Cells["A4"].Value = 4;
worksheet.Cells["A5"].Value = 5;
worksheet.Cells["A6"].Value = 6;
worksheet.Cells["B1"].Value = 10000;
worksheet.Cells["B2"].Value = 10100;
worksheet.Cells["B3"].Value = 10200;
worksheet.Cells["B4"].Value = 10150;
worksheet.Cells["B5"].Value = 10250;
worksheet.Cells["B6"].Value = 10200;
//ExcelChart chart = worksheet.Drawings.AddChart("LineChart", eChartType.XYScatterSmooth);
ExcelChart chart = worksheet.Drawings.AddChart("LineChart", eChartType.XYScatterSmoothNoMarkers);
chart.Series.Add(ExcelRange.GetAddress(1, 2, worksheet.Dimension.End.Row, 2),
ExcelRange.GetAddress(1, 1, worksheet.Dimension.End.Row, 1));
var Series = chart.Series[0];
//chart.Axis[0].MinorGridlines.Fill.Color = Color.Red;
//chart.Axis[0].MinorGridlines.LineStyle = eLineStyle.LongDashDot;
chart.Axis[0].RemoveGridlines();
chart.Axis[1].RemoveGridlines();
chart.Axis[0].Border.LineStyle = eLineStyle.SystemDash;
//chart.XAxis.Border.LineStyle = eLineStyle.Dash;
chart.Series[0].Header = "Blah";
//chart.Series[0].Border.LineStyle = eLineStyle.DashDot;
//chart.Axis[0].Border.LineStyle = eLineStyle.Dash;
xlPackage.Save();
MessageBox.Show("Done");
}
I also check this post but could not implement it in my code Office Open XML: Drawing Dashed Line in Chart
Please push me to right direction to achieve my goal. Thanks in advance.
This works for me with same versions as you.
You need to add a reference to System.Drawing for the color:
// ...(code above this line did not change)
ExcelChart chart = worksheet.Drawings.AddChart("LineChart", eChartType.XYScatterSmoothNoMarkers);
chart.Series.Add(
ExcelRange.GetAddress(1, 2, worksheet.Dimension.End.Row, 2),
ExcelRange.GetAddress(1, 1, worksheet.Dimension.End.Row, 1));
chart.Series[0].Header = "Blah";
// Add this:
chart.Series[0].Border.LineStyle = OfficeOpenXml.Drawing.eLineStyle.Dash;
chart.Series[0].Border.Width = 2;
chart.Series[0].Border.Fill.Color = System.Drawing.Color.Blue;
chart.Axis[0].RemoveGridlines();
chart.Axis[1].RemoveGridlines();
xlPackage.Save();
Result:
#region chart summary 4
ExcelWorksheet Worksheet4 = p.Workbook.Worksheets.Add("Graph(4)");
var summary_Chart_four = Worksheet4.Drawings.AddChart("chart", eChartType.LineMarkers);
// var summary_Chart_four = Worksheet4.Drawings.AddChart("chart", eChartType.XYScatterLines) as ExcelScatterChart;
//var summary_Chart_four = Worksheet4.Drawings.AddChart("chart", (eChartType)System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash);
//var summary_Chart_four = myWorksheet.Drawings.AddChart("chart", (eChartType)System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash);
summary_Chart_four.ShowDataLabelsOverMaximum = true;
Worksheet4.Cells.Style.Font.Name = "Arial";
Worksheet4.Cells.Style.Font.Size = 10;
Worksheet4.Cells.Style.Font.Bold = false;
loopCnt = 0;
for (int i = 0; i < (cVM.PeerGroups.Count + cVM.IndexGroups.Count) * 4; i += 4)
{
int rowIndex = 10 + i;
int endRowIndex = 14 + i;
string startingColumn_series = "C" + rowIndex;
string endColumn_series = column + rowIndex;
string lastColumn_xaxis = column + 6;
int headerRowIndex = 9 + i;
string seriesHeader = "A" + headerRowIndex;
var series_i = summary_Chart_four.Series.Add(myWorksheet_summary_data.Cells[startingColumn_series + ":" + endColumn_series], myWorksheet_summary_data.Cells["C6:" + lastColumn_xaxis]);//working
series_i.Header = myWorksheet_summary_data.Cells[seriesHeader].Value.ToString();
summary_Chart_four.YAxis.Font.Size = 10;
summary_Chart_four.XAxis.Font.Size = 10;
//summary_Chart_four.XAxis.Format =DateTime.Now.Year.ToString();
summary_Chart_four.YAxis.Format = "$0";
if (loopCnt == 0)
{
string LineColor = "#000080";
series_i.Border.LineStyle = eLineStyle.Solid;
//series_i.LineColor = LineColor.ConvertToColor();
//series_i.LineWidth = 2.0;
//series_i.Marker.Style = eMarkerStyle.Diamond;
//series_i.Marker.Size = 8;
//string BGColor = "#99ccff";
//series_i.Marker.Fill.Color = BGColor.ConvertToColor();
//string strBorderColor = "#000080";
//series_i.Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineColor = LineColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineWidth = 2.0;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Diamond;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Size = 8;
string BGColor = "#99ccff";
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.LineCap
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Fill.Color = BGColor.ConvertToColor();
string strBorderColor = "#000080";
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Width = 0.75;
}
else if (loopCnt == 1)
{
string LineColor = "#003300";
series_i.Border.LineStyle = eLineStyle.LongDash;
//series_i.LineColor = LineColor.ConvertToColor();
//series_i.LineWidth = 2.0;
//series_i.Marker.Style = eMarkerStyle.Square;
////((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Dash;
//series_i.Marker.Size = 7;
string BGColor = "#c0c0c0";
//series_i.Marker.Fill.Color = BGColor.ConvertToColor();
//string strBorderColor = "#003300";
//series_i.Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineColor = LineColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineWidth = 2.0;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Square;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Size = 7;
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.LineCap
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Fill.Color = BGColor.ConvertToColor();
string strBorderColor = "#003300";
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Width = 0.75;
}
else if (loopCnt == 2)
{
string LineColor = "#F79646";
series_i.Border.LineStyle = eLineStyle.Dot;
////series_i.LineColor = LineColor.ConvertToColor();
////series_i.LineWidth = 2.0;
////series_i.Marker.Style = eMarkerStyle.Circle;
//////((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Dot;
////series_i.Marker.Size = 8;
string BGColor = "#ccffcc";
////series_i.Marker.Fill.Color = BGColor.ConvertToColor();
string strBorderColor = "#F79646";
////series_i.Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineColor = LineColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineWidth = 2.0;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Circle;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Size = 8;
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.LineCap
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Fill.Color = BGColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Width = 0.75;
}
else if (loopCnt == 3)
{
string LineColor = "#c0504d";
series_i.Border.LineStyle = eLineStyle.LongDashDotDot;
////series_i.LineColor = LineColor.ConvertToColor();
////series_i.LineWidth = 2.0;
////series_i.Marker.Style = eMarkerStyle.Triangle;
//////((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Dot;
////series_i.Marker.Size = 8;
string BGColor = "#c0504d";
////series_i.Marker.Fill.Color = BGColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineColor = LineColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).LineWidth = 2.0;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Triangle;
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Size = 8;
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.LineCap
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Fill.Color = BGColor.ConvertToColor();
string strBorderColor = "#003300";
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Fill.Color = strBorderColor.ConvertToColor();
((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Border.Width = 0.75;
}
//else if (loopCnt == 4)
//{
// string LineColor = "#c0504d";
// series_i.Border.LineStyle = eLineStyle.LongDashDotDot;
// series_i.LineColor = LineColor.ConvertToColor();
// series_i.LineWidth = 1.5;
// series_i.Marker.Style = eMarkerStyle.Square;
// //((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Marker.Style = eMarkerStyle.Dot;
// series_i.Marker.Size = 8;
// string BGColor = "#c0504d";
// series_i.Marker.Fill.Color = BGColor.ConvertToColor();
//}
else
{
////series_i.LineColor = System.Drawing.Color.Aqua;
////series_i.LineWidth = 1.5;
////series_i.Marker.Style = eMarkerStyle.Circle;
////series_i.Marker.Size = 8;
////series_i.Marker.Fill.Color = System.Drawing.Color.Aqua;
}
//series_i.Smooth = eLineStyle.Dash;
//((OfficeOpenXml.Drawing.Chart.ExcelLineChartSerie)series_i).Series=eChartType.d
loopCnt++;
}
//var series_four = summary_Chart_four.Series.Add(myWorksheet_summary_data.Cells["C10:" + lastColumn_series1], myWorksheet_summary_data.Cells["C6:" + lastColumn_xaxis]);//working
//series_four.Header = myWorksheet_summary_data.Cells["A9"].Value.ToString();
//var series_four1 = summary_Chart_four.Series.Add(myWorksheet_summary_data.Cells["C14:" + lastColumn_series2], myWorksheet_summary_data.Cells["C6:" + lastColumn_xaxis]);
//series_four1.Header = myWorksheet_summary_data.Cells["A13"].Value.ToString();
summary_Chart_four.Border.Fill.Color = System.Drawing.Color.Black;
//summary_Chart_four.Title.Text = "Comparison of " + cVM.YearsBack + " Year Cumulative Total Return" + Environment.NewLine + " Assumes Initial Investment of $100" + Environment.NewLine + strMonth + " " + strSelectedDt.Year;
summary_Chart_four.Title.Text = "COMPARISON OF CUMULATIVE TOTAL RETURN";
summary_Chart_four.SetSize(960, 600);
// Add to 6th row and to the 6th column
summary_Chart_four.Legend.Font.Size = 10;
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).Legend.Font.SetFromFont("Calibri", 11, false, false, false, false);
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).YAxis.Font.SetFromFont("Arial", 10, false, false, false, false);
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).XAxis.Font.SetFromFont("Arial", 10, false, false, false, false);
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).Title.Font.Bold = true;
((OfficeOpenXml.Drawing.Chart.ExcelChartStandard)summary_Chart_four).Title.Font.SetFromFont("Calibri", 16, false, false, false, false);
//summary_Chart_four.Legend.Border.Fill.Color = System.Drawing.Color.Black;
summary_Chart_four.SetPosition(0, 0, 0, 0);
summary_Chart_four.XAxis.MajorTickMark = eAxisTickMark.In;
//summary_Chart.XAxis.MajorTickMark = eAxisTickMark.In;
summary_Chart_four.XAxis.MinorTickMark = eAxisTickMark.None;
summary_Chart_four.YAxis.MinorTickMark = eAxisTickMark.None;
summary_Chart_four.Legend.Position = eLegendPosition.Top;
summary_Chart_four.YAxis.CrossBetween = eCrossBetween.MidCat;
summary_Chart_four.XAxis.MajorGridlines.CompoundLineStyle = eCompundLineStyle.Double;
I am trying to display points from 7 files. Each file corresponds to a day, and I am trying to add a button where it takes the last 7 created files and displays them as x=dateTime and y= value. what this code currently does is that only displays the x axis on the left and right side.
private void button1_Click(object sender, EventArgs e)
{
chart1.Titles.Clear();
chart1.Series.Clear();
xAxis.Clear();
yAxis.Clear();
var Series1 = new Series
{
Name = comboBox2.Text,
Color = System.Drawing.Color.Green,
IsVisibleInLegend = false,
IsXValueIndexed = true,
ChartType = SeriesChartType.Area
};
this.chart1.Series.Add(Series1);
double measur = 0;
//clear graph
string Folder = #"\\Engineer\DI-808\outlooktest\";
var files = new DirectoryInfo(Folder).GetFiles("*_*");
string latestfile = "";
DateTime lastModified = DateTime.MinValue;
List<string> filesD = new List<string>();
DateTime endDate=DateTime.Now;
DateTime startDate= DateTime.Now.AddDays(-3);
DateTime dateToCheck;
Console.WriteLine(startDate + " " + endDate);
foreach (FileInfo file in files)
{
//Console.WriteLine(file.Name+"before");
string edited = file.Name.Remove(0, 6);
//Console.WriteLine(edited+"during");
char[] csv = { '.', 'c', 's', 'v'};
edited = edited.TrimEnd(csv);
//Console.WriteLine(edited + "after CSV");
edited = edited.Remove(10, 9);
// Console.WriteLine(edited+"after");
dateToCheck = Convert.ToDateTime(edited);
Console.WriteLine(dateToCheck+" date to check");
Console.WriteLine(startDate+" start");
Console.WriteLine(endDate+ " end" );
// if ( DateTime.Compare(dateToCheck,startDate)>=0dateToCheck >= startDate && dateToCheck <= endDate);
if (DateTime.Compare(dateToCheck, startDate)>=0 && DateTime.Compare(dateToCheck, endDate)<=0)
{
latestfile = file.Name;
filesD.Add(latestfile);
Console.WriteLine(latestfile+" dweeb");
}
}
Console.WriteLine(filesD.Count());
for (int i = 0; i < filesD.Count(); i++)
Console.WriteLine(files[i]);
string lineData;
try
{
for (int i=0;i<filesD.Count();i++) {
readData = new StreamReader(#"\\egvfps1.egv.mapes.local\Engineer\DI-808\outlooktest\" + filesD[i]);
for (int k = 0; k < 21; k++)
readData.ReadLine();
while ((lineData = readData.ReadLine()) != null)
{
if (Convert.ToDouble(lineData.Split(',')[comboBox2.SelectedIndex + 2]) <= 0.001)
measur = 0;
else
{
measur = Convert.ToDouble(lineData.Split(',')[comboBox2.SelectedIndex + 2]) * 110;
xAxis.Add(Convert.ToDateTime(lineData.Split(',')[1]));
yAxis.Add(measur);
}
}
}
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
}
readData.Close();
this.chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
this.chart1.Titles.Add(comboBox2.Text + "(" + xAxis[0].ToString("MM/dd/yyyy") + ")");
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Hours;
chart1.ChartAreas[0].AxisX.Interval = 1;
// chart1.ChartAreas[0].AxisX.MajorGrd.Enabled = false;
//chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chart1.ChartAreas.FirstOrDefault().AxisX.Interval = 1;
// chart1.ChartAreas.FirstOrDefault().AxisY.Interval = 1;
for (int i = 0; i < xAxis.Count(); i++)
{
chart1.Series[comboBox2.Text].Points.AddXY(xAxis[i], yAxis[i]);
}
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Hours;
chart1.ChartAreas[0].AxisX.Interval = 1;
// chart1.ChartAreas[0].AxisX.MajorGrd.Enabled = false;
//chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
chart1.ChartAreas.FirstOrDefault().AxisX.Interval = 1;
// chart1.ChartAreas.FirstOrDefault().AxisY.Interval = 1;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Hours;
chart1.ChartAreas[0].AxisX.IntervalOffset = 1;
chart1.Series[0].XValueType = ChartValueType.DateTime;
}
enter image description here
I know its somewhere in the Xaxis interval type part,but I don't know what values to put in.
Any suggestions helps!
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'm currently looping through a JSON array and generating an object for each item in the array.
I wondering how I can parse data from the current object.
int i = 0, count = 0, yMP, yGP, yGT, favscountB8 = 0;
string gamertag;
JObject o1 = JObject.Parse(File.ReadAllText(#"gamerprofile.json"));
string jsonGamerprofile = JsonConvert.SerializeObject(o1);
var resultObjects = AllChildren(JObject.Parse(jsonGamerprofile))
.First(c => c.Type == JTokenType.Array && c.Path.Contains("favorites"))
.Children<JObject>();
foreach (JObject result in resultObjects)
{
// Here I wish to make the string gamertag = the value of (FavsGTS_gpF) which is inside the current object.
favscountB8 = favscountB8 + 1;
count = count + 1;
yMP = 6 + (62 * (count - 1));
yGP = 7 + (62 * (count - 1));
yGT = 11 + (62 * (count - 1));
Panel mainpanel1 = new Panel();
PictureBox gamerpic1 = new PictureBox();
Label gamertag1 = new Label();
mainpanel1.BackColor = Color.Red;
mainpanel1.Location = new Point(6, yMP);
mainpanel1.Size = new Size(957, 60);
mainpanel1.Name = "mainpanel" + i.ToString();
gamerpic1.BackColor = Color.Azure;
gamerpic1.Location = new Point(7, yGP);
gamerpic1.Size = new Size(54, 54);
gamerpic1.Name = "gamerpic" + i.ToString();
gamerpic1.BringToFront();
gamertag1.ForeColor = Color.FromArgb(110, 120, 127);
gamertag1.BackColor = Color.White;
gamertag1.Text = "Gamertag " + count.ToString();
gamertag1.Font = new Font("Arial Narrow", 14, FontStyle.Bold);
gamertag1.Location = new Point(76, yGT);
gamertag1.Size = new Size(145, 23);
gamertag1.Name = "Gamertag " + count.ToString();
gamertag1.BringToFront();
i = i + 1;
panel4.Controls.Add(gamertag1);
panel4.Controls.Add(gamerpic1);
panel4.Controls.Add(mainpanel1);
}
Inside the foreach statement I wish to make the "gamertag" string equal to the value of "FavsGTS_gpF" which is in each object in the array.
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