labeling a legend in epplus - c#

I'm trying to create a graph from some data I export to an .xls file. I create the graph just fine, but I'm going to have anywhere from 3 - 7 lines on the graph. I added the legend to make it easier to read, but the legend has no text on it. It just shows a line without a label. Is there anyway to label the legend key?
Here's the code of the graph I'm making:
var lineChart = ws.Drawings.AddChart(item.TestHeader, eChartType.Line) as ExcelLineChart;
lineChart.SetSize(800, 400);
lineChart.Series.Add(Char.ConvertFromUtf32(65 + distanceCount + 1).ToString() + "1:" + Char.ConvertFromUtf32(65 + distanceCount + 1).ToString() + (testCount.ToString()), "A1:A" + (testCount.ToString()));
lineChart.Title.Text = item.TestHeader;
lineChart.DataLabel.ShowSeriesName = true;
lineChart.DataLabel.ShowLegendKey = true;
lineChart.DataLabel.ShowLeaderLines = true;
lineChart.XAxis.Title.Text = "Inches from Decoder";
lineChart.YAxis.Title.Text = "Milliseconds to decode";
lineChart.YAxis.MaxValue = 1000;
Any help is better than none, thanks!

Your example generated a series name in the legend for me named "Series". But you can set it explicitly using
lineChart.Series[0].Header = "Series 1 Name";

Related

How to add multiple fonts to a single line of text with iTextSharp

In plant classification the family-genus-species is normally written in italics with any variety in normal text.
Rosaceae Sorbus aucuparia 'Fastigiata'
I'm trying to achieve this in c# using the iTextSharp library. Could anyone help?
I've made two different font objects. Added each one to two different chunk objects and then added the chunks to a phrase object before finally adding the phrase to a table cell.
Current output is the whole line is in italics.
Rosaceae Sorbus aucuparia 'Fastigiata'
iTextSharp.text.Font fontHeader = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 15f);
iTextSharp.text.Font fontHeaderItalic = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 15f, iTextSharp.text.Font.ITALIC);
Phrase phrase = new Phrase(new Chunk(plant.strFamily + " " + plant.strGenus + " " + plant.strSpecies, fontHeaderItalic));
if(plant.strVariety != null)
phrase.Add(new Chunk(" '" + plant.strVariety + "'", fontHeader));
tableHeader.AddCell(new PdfPCell(phrase) { Border = 0 });

out of memory exception with grid in scrollviewer

I am very new in developing apps with C# for WP 8.1 Silverlight.
I developed an app to display data from a csv-file.
The data is displayed in a grid within a scrollviewer element with 7 columns.
All works fine. But when the app gets more then 600 lines from the csv-file the app crashes with an out of Memory exception.
How can I avoid this? It should be no problem to display 600 lines of text in a grid.
See my code:
//insert lines:
//Row create:
reihe1 = new RowDefinition();
reihe1.Height = new GridLength(zeilenhoehe);
grid_umsatzdetail.RowDefinitions.Add(reihe1);
reihe1 = null;
//Columns create:
//first column date:
textblock_name = dateizeile + "|" + index_daten + "|" + "0";
TextBlock textblock_new_datum = new TextBlock();
textblock_new_datum.Name = textblock_name;
textblock_new_datum.Height = zeilenhoehe;
textblock_new_datum.Width = Double.NaN;
textblock_new_datum.FontSize = schriftgroesse;
textblock_new_datum.Text = " " + teile[0] + " ";
Grid.SetRow(textblock_new_datum, zaehler_reihe);
Grid.SetColumn(textblock_new_datum, 0);
grid_umsatzdetail.Children.Add(textblock_new_datum);
textblock_new_datum = null;
//border insert into grid:
rand = new Border();
rand.BorderThickness = new Thickness(1);
rand.BorderBrush = new SolidColorBrush(Colors.White);
rand.Width = Double.NaN;
rand.Height = zeilenhoehe_head;
Grid.SetRow(rand, zaehler_reihe);
Grid.SetColumn(rand, 0);
grid_umsatzdetail.Children.Add(rand);
rand = null;
//second column amount:
... same coding as above for every column ...
I am really happy for any tips!

Using a variable to access a chart

I have a C# WinForms application that has four chart controls used to graphically show some analysis results.
I have the code working for each graph, however in an attempt to be more efficient & re-use code I've defined a code block to:
create the required series,
extracts the data from a database & assigns the results to the appropriate series
add the series to the chart
customise the charts appearance.
All of the above is done dynamically as the data does not exist at design time.
The working code I am looking to re-use is:
// Add both series to the chart.
ChartName.Series.AddRange(new Series[] { series1, series2 });
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)ChartName.Diagram;
I'd like to change the ChartName object to a variable that I can pass each of the charts in order to re-use the code. Something like (note this does not work):-
var VChart = this.Controls.Find(ChartName, true);
// Add both series to the chart.
VChart.Series.AddRange(new Series[] { series1, series2 });
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)VChart.Diagram;
Any ideas, hints, tips, etc on how-to pass a variable into the ChartName would be appreciated.
Full Code:
void Generate_Chart()
{
// Create two stacked bar series.
Series series1 = new Series("Data", ViewType.Bar);
Series series2 = new Series("Ben", ViewType.Line);
try
{
using (var cmd = new SQLiteCommand(m_dbConnection))
for (int i = LoopMin; i < LoopMax; i++)
{
// Retrieve the actual calculated values from the database
cmd.CommandText = "SELECT " + Chart_SourceActualValue + " FROM " + Chart_SourceTable + " WHERE Value = " + i + "";
Chart_SeriesA_Value = Convert.ToInt32(cmd.ExecuteScalar());
// Retrieve the expected values from the database
cmd.CommandText = "SELECT " + Chart_BenExpValue + " FROM " + Chart_SourceTable + " WHERE Value = " + i + "";
Chart_SeriesB_Value = Convert.ToInt32(cmd.ExecuteScalar());
// Add the dynamically created values to a series point for the chart
series1.Points.Add(new SeriesPoint(i, Chart_SeriesA_Value));
series2.Points.Add(new SeriesPoint(i, Chart_SeriesB_Value));
}
}
catch (Exception)
{
throw;
}
// Add both series to the chart.
//this.Controls.Find(varChart, true)
ChartName.Series.AddRange(new Series[] { series1, series2 });
// Remove the GridLines from the chart for better UI
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)ChartName.Diagram;
// Customize the appearance of the axes' grid lines.
diagram.AxisX.GridLines.Visible = false;
}
}
It sounds like you're asking to replace the hardcoded ChartName with a variable so that you can call your routine four different times, each time with a different chart. I've taken your code and replaced some of the global variable of your chart control and settings and and made them parameters you pass into the function:
void Generate_Chart(DevExpress.XtraCharts.ChartControl chartCtrl,
string chart_sourceActualValue,
string chart_sourceTable,
string chart_benExpValue
)
{
// Create two stacked bar series.
Series series1 = new Series("Data", ViewType.Bar);
Series series2 = new Series("Ben", ViewType.Line);
try
{
using (var cmd = new SQLiteCommand(m_dbConnection))
for (int i = LoopMin; i < LoopMax; i++)
{
// Retrieve the actual calculated values from the database
cmd.CommandText = "SELECT " + sourceActualValue + " FROM " +
chart_sourceTable + " WHERE Value = " + i + "";
Chart_SeriesA_Value = Convert.ToInt32(cmd.ExecuteScalar());
// Retrieve the expected values from the database
cmd.CommandText = "SELECT " + chart_benExpValue + " FROM " +
chart_sourceTable + " WHERE Value = " + i + "";
Chart_SeriesB_Value = Convert.ToInt32(cmd.ExecuteScalar());
// Add the dynamically created values
// to a series point for the chart
series1.Points.Add(new SeriesPoint(i, Chart_SeriesA_Value));
series2.Points.Add(new SeriesPoint(i, Chart_SeriesB_Value));
}
}
catch (Exception)
{
throw;
}
// Add both series to the chart.
chartCtrl.Series.AddRange(new Series[] { series1, series2 });
// Remove the GridLines from the chart for better UI
// Cast the chart's diagram to the XYDiagram type, to access its axes.
XYDiagram diagram = (XYDiagram)chartCtrl.Diagram;
// Customize the appearance of the axes' grid lines.
diagram.AxisX.GridLines.Visible = false;
}
}
Then, you end up calling this method like this using the original values as arguments:
void Generate_Chart(ChartName, Chart_SourceActualValue, Chart_SourceTable,
Chart_BenExpValue);
// call it three other times passing in the different specifics for that chart. e.g.
void Generate_Chart(SomeOtherChartName, SomeOtherChart_SourceActualValue,
SomeOhterChart_SourceTable, SomeOtherChart_BenExpValue);
.....

label printer incorrectly prints itextsharp documents

the code below generate pdf documents:
using (FileStream fs = new FileStream("st.csv", FileMode.Open))
{
using (StreamReader configFile = new StreamReader(fs, System.Text.Encoding.GetEncoding("windows-1250")))
{
string line = string.Empty;
while ((line = configFile.ReadLine()) != null)
{
if (!string.IsNullOrEmpty(line))
{
line = line.Replace("\"", "");
string[] varible = line.Split(';');
string number = varible[0];
string stName = varible[1];
string ewidenceNumber = varible[2];
string fileName = "barcodes\\" + Encryption.RandomString(10, true) + ".png";
Generate(line, fileName);
PdfPTable Table = new PdfPTable(2);
Table.WidthPercentage = 100;
Table.SetWidths(new[] { 110f, 190f });
iTextSharp.text.Image barcode = iTextSharp.text.Image.GetInstance(fileName);
barcode.Border = 0;
barcode.ScalePercent(180f);
PdfPCell imageCell = new PdfPCell(barcode);
imageCell.VerticalAlignment = Element.ALIGN_MIDDLE;
Table.AddCell(imageCell);
PdfPCell descriptionCell = new PdfPCell(new Paragraph(
"Enterprise 1 \n\n" +
number + "\n\n" +
"Number1: " + stName + "\n\n" +
"Number2: " + ewidenceNumber, _standardFont));
descriptionCell.HorizontalAlignment = Element.ALIGN_CENTER;
descriptionCell.VerticalAlignment = Element.ALIGN_MIDDLE;
Table.AddCell(descriptionCell);
Table.KeepTogether = true;
Table.SpacingAfter = 10f;
doc.Add(Table);
}
}
}
}
and here is the problem: vertical and horizontal view in adobe acrobat displays correctly, but when I need to print labels with this information CITIZEN label printer always prints it in horizontal view. I can't adapt this data to print in correct orientation. Anyone has solution for this problem? Maybe I incorrectly rotate cells in table?
I would suggest you drop PDF and instead write to it's native format: http://www.citizen-europe.com/support/progman.htm
PDF printing support is supplied by the driver. If the driver doesn't know how to interpret the specific PDF commands then it's not going to work. Usually label printers don't provide very good driver support for anything but writing to their native format or emulating ZPL (zebra) and Datamax.

how to collect value from dynamic input and steps in ASP.NET Wizard

I'm trying to create a dynamic survey form based on dynamic data by using ASP.NET Wizard.
I can create dynamic steps and dynamic inputs without any problem. However, the last step, when I submit the form, I won't be able to collect all information from each steps.
Any idea?
Wizard wizard1 = new Wizard();
wizard1.Style.Add("width", "100%");
//wizard1.DisplaySideBar = false;
for (int i = 1; i <= 3; i++)
{
WizardStep step1 = new WizardStep();
step1.ID = "step" + i.ToString();
step1.Title = "step" + i.ToString();
PlaceHolder ph = new PlaceHolder();
ph.ID = "ph" + i.ToString();
ph.Controls.Add(new LiteralControl("<h1>Step." + i.ToString() + "</h1>"));
TextBox tb = new TextBox();
tb.ID = "step" + i.ToString() + "tb";
ph.Controls.Add(tb);
step1.Controls.Add(ph);
wizard1.WizardSteps.Add(step1);
}
wizard1.FinishButtonClick += atWizardCompleted;
wizard_container.Controls.Add(wizard1);
well, I found the solution by using Control.Find().

Categories

Resources