How to show dates in a chart in Report Viewer? - c#

I asked a question
How to show dates in a chart in Excel?
I solved that in Excel, But I have the same problem in Report Viewer. It shifts data (related to the previous year) to the right side of the chart.
My date data is in string format.
List<Report> tempList = new List<Report>();
foreach (DataRow row in DT.Rows)
{
Report temp = new Report();//class
temp.Row = Convert.ToInt16(row["Row"].ToString());
temp.Date = row["Date"].ToString();
temp.Value= Convert.ToDouble(row["Value"].ToString());
tempList.Add(temp);
}
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
string reportEmbeddedResource = "ETc.Report1.rdlc";
reportDataSource1.Name = "DataSet1";
reportDataSource1.Value = this.ReportBindingSource;
this.reportViewer.LocalReport.DataSources.Add(reportDataSource1);
this.reportViewer.LocalReport.ReportEmbeddedResource = reportEmbeddedResource;
this.ReportBindingSource.DataSource = tempList;
this.reportViewer.RefreshReport();

OK.
In 'Category Group Properties...' --> in 'Sorting' section, change sort type (if you have a uniqe value for each row) or delete it.

Related

FastReport fetch data without DataGridView

I have this project on c# windows forms and what I have to do is get some data from a web service and present them to FastRaport.
I have tried display them on a DataGridView first and then fetching the data from it and it works pretty nice. I can download the file and then it gives me a dialog asking me in what format do I want to save it.
But now the requirement is to not use gridview at all, just a button that would convert directly those data into a PDF file.
Here's my code for displaying the data into DataGridView:
var asd1 = dataGridView1.Columns.Add("DrzavaAng", "DrzavaAng");
var asd2 = dataGridView1.Columns.Add("Valuta", "Valuta");
var asd3 = dataGridView1.Columns.Add("Oznaka", "Oznaka");
var asd4 = dataGridView1.Columns.Add("Nomin", "Nomin");
var asd5 = dataGridView1.Columns.Add("Sreden", "Sreden");
for (var i = 0; i<xmlNodes.Count; i++)
{
var node = xmlNodes[i];
var states = new Class();
states.Valuta = node["Valuta"].InnerText;
states.Oznaka = node["Oznaka"].InnerText;
states.Nomin = node["Nomin"].InnerText;
states.Sreden = node["Sreden"].InnerText;
states.DrzavaAng = node["DrzavaAng"].InnerText;
//var asd = dataGridView1.Columns.Add("1", "1");
_ = dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells["DrzavaAng"].Value=states.DrzavaAng;
dataGridView1.Rows[i].Cells["Valuta"].Value=states.Valuta;
dataGridView1.Rows[i].Cells["Oznaka"].Value=states.Oznaka;
dataGridView1.Rows[i].Cells["Nomin"].Value=states.Nomin;
dataGridView1.Rows[i].Cells["Sreden"].Value=states.Sreden;
}
Here's the part where I pass the data from GridView to the FastReport "database".
using (Report report = new Report())
{
report.Load(ReportPath);
DataTable dt = new DataTable();
foreach (DataGridViewColumn cl in dataGridView1.Columns)
{
dt.Columns.Add();
}
object[] clvl = new object[dataGridView1.Columns.Count];
foreach (DataGridViewRow row in dataGridView1.Rows)
{
for (int i = 0; i<row.Cells.Count; i++)
{ clvl[i] = row.Cells[i].Value; }
dt.Rows.Add(clvl);
}
DataSet ds = new DataSet();
ds.Tables.Add(dt);
report.Dictionary.RegisterData(ds.Tables[0], "test", true);
report.SetParameterValue("date", dateTimePicker1.Value.ToString("dd.MM.yyyy"));
report.Show();
}
Here's my FastReport file before committing anything:
FastReportImage
And here's the output I get : FastReport output
My question is, how can I make it to fetch the data without the gridview, directly from webservice and load it into a FastReport -> PDF file?

Cannot convert System.Data.Datarow to System.DateTime

I have a Datatable and DataRows in it, and those DataRows gets the value from a XML file.
DataRow row = table.NewRow();
row["InvoiceNumber"] = xmlData.ChildNodes[2].ChildNodes[0].ChildNodes[2].ChildNodes[0].InnerText;
row["InvoiceIssueDate"] = Convert.ToDateTime(xmlData.ChildNodes[2].ChildNodes[0].ChildNodes[2].ChildNodes[1].InnerText);
row["InvoiceDeliveryDate"] = Convert.ToDateTime(xmlData.ChildNodes[2].ChildNodes[0].ChildNodes[2].ChildNodes[2].InnerText);
But when I want to add those rows to my Entity Framework table that's error comes.
Invoices invoices = new Invoices();
invoices.InvoiceNumber = table.Rows[0].ToString();
invoices.InvoiceIssueDate = table.Rows[1];
invoices.InvoiceDeliveryDate = table.Rows[2];
How should I convert them?
try this.
invoices.InvoiceIssueDate = Convert.ToDateTime(table.Rows[1]);
invoices.InvoiceDeliveryDate = Convert.ToDateTime(table.Rows[2]);

Adding legend to winforms point chart

I am building a winform point chart using C# where the data comes from a datatable. I've created the points like this:
chart1.Series.Add("series1");
chart1.Series["series1"].ChartType = SeriesChartType.Point;
chart1.Series["series1"].YValueMembers = "VALUE";
chart1.Series["series1"].XValueMember = "DATE";
chart1.DataSource = dt;
I'd like to be able make a legend of the points on the chart using different colors/symbols based on a third column in the datatable dt called product. I've tried a number of things to get this done but nothing is working. How can I accomplish this?
You can use this code I got from msdn page
// Create a new legend called "Legend2".
chart1.Legends.Add(new Legend("Legend2"));
// Set Docking of the Legend chart to the Default Chart Area.
chart1.Legends["Legend2"].DockToChartArea = "Default";
// Assign the legend to Series1.
chart1.Series["Series1"].Legend = "Legend2";
chart1.Series["Series1"].IsVisibleInLegend = true;
Part of my problem was first understanding how to construct charts in the first place. I realized I needed to create a series for each unique product in my datatable and add those to the chart. I first made a list of unique products in the datatable:
List<string> products = new List<string>();
foreach (DataRow row in dt.Rows)
{
if (!products.Contains(row["product"].ToString()))
{
products.Add(row["product"].ToString());
}
}
Then
foreach (string product in products)
{
string seriesName = product;
chart1.Series.Add(seriesName);
DataTable dtprod = new DataTable();
dtprod = dt.Select("product= '" + product + "'").CopyToDataTable();
chart1.Series[seriesName].ChartType = SeriesChartType.Point;
chart1.Series[seriesName].YValueMembers = "VALUE";
chart1.Series[seriesName].XValueMember = "DATE";
chart1.Series[seriesName].Points.DataBindXY(dtprod.Rows,"DATE", dtprod.Rows, "VALUE");
chart1.Series[seriesName].XValueType = ChartValueType.DateTime;
chart1.Series[seriesName].MarkerSize = 10;
}
This produced a point chart with a unique marker for each product. Thanks for your answers!

Crystal report not showing any data

I am new to C# and ASP .NET programming. I am making a crystal report in .net. I setup Dataset and DataTable. For report sources.
I am getting data from a linq query. and after that I am populating them in a instance of Dataset. I use debugger and it shows that I have data from the query. But my crystal reeport just shows the column heading not the column data.
Here is my code:
private void ViewReport()
{
DataSet1 Dataset = new DataSet1();
DataTable rptTable = Dataset.Tables["Emp_info"];
DataTable rptTab = Dataset.Tables["Attendance_table"];
Ind_attendance_rpt rptAtd = new Ind_attendance_rpt();
DataRow dataRow1; // declaring Row of dataset
DataRow dataRow2;
//IndividualAttendance rptAtt = new IndividualAttendance();
var rport = from att in db.Attendance_tables
join emp in db.Emp_infos on att.Login_id equals emp.ID
orderby att.Id
select new
{
att.Id,
emp.Emp_name,
emp.ID,
emp.Designation,
emp.Dept,
att.Entry_time,
att.Exit_time,
att.Status,
att.Date
};
Dataset.Tables["Emp_info"].Clear();
Dataset.Tables["Attendance_table"].Clear();
foreach (var rt in rport)
{
dataRow1 = rptTable.NewRow();
dataRow2 = rptTab.NewRow();
dataRow2["Id"] = rt.Id;
dataRow1["Emp_name"] = rt.Emp_name;
dataRow1["Designation"] = rt.Designation;
dataRow1["Dept"] = rt.Dept;
dataRow2["Entry_time"] = rt.Entry_time;
dataRow2["Exit_time"] = rt.Exit_time;
dataRow2["Status"] = rt.Status;
dataRow2["Date"] = rt.Date;
dataRow2["Login_id"] = rt.ID;
Dataset.Tables["Emp_info"].Rows.Add(dataRow1);
Dataset.Tables["Attendance_table"].Rows.Add(dataRow2);
}
rptAtd.SetDataSource(Dataset);
CrystalReportViewer1.ReportSource = rptAtd;
}
Can anyone tell me the reason?
Here is the result I am getting right now:
Debug Image:
Try to call Refresh on the report after setting the ReportSource
CrystalReportViewer1.Refresh();
you may have to use ToList() on your linq as well;

Ajax Pie Chart C# modify properties

Here is an image of my pie chart now
Here is the c# code for it..
string query = string.Format("select TestName,Count (TestName) AS Counts from VExecutionGlobalHistory where Tester <> 'dit2988' AND TestTypeID = 1 group by TestName", ddlTests.SelectedItem.Value);
DataTable dt = GetData(query);
foreach (DataRow row in dt.Rows)
{
SpecificTestsWeb6.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
{
Category = row["TestName"].ToString(),
Data = Convert.ToDecimal(row["Counts"]),
}
);
}
SpecificTestsWeb6.ChartTitle = "Specific Tests Run";
I need to align the bottom values to the left so i can see them all. I would also like to be able to manually asign colors so there are no repeats. Thanks.
var random = new Random();
foreach (DataRow row in dt.Rows)
{
var color = String.Format("#{0:X6}", random.Next(0x1000000));
SpecificTestsRapp.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
{
Category = row["TestName"].ToString(),
Data = Convert.ToDecimal(row["Counts"]),
PieChartValueColor = color
});
}
SpecificTestsRapp.ChartTitle = "Specific Tests Run";

Categories

Resources