Report 2 Example for Blazor

Nevron NOV RichTextEditor for Blazor ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All Blazor RichTextEditor examples are also available as a stand-alone Visual Studio solution in C#, which you can download from the links below.

Report 2 Example for Blazor Description

This example demonstrates how to programmatically create reports as well as how to collect text elements of different type.


Sample Report 2Example

C# Report 2 Example Code for Nevron RichTextEditor for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NSampleReport2Example";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

		#region Example

		public NWidget CreateExampleContent()
		{
			// Create the rich text
			NRichTextViewWithRibbon richTextWithRibbon = new NRichTextViewWithRibbon();
			m_RichText = richTextWithRibbon.View;
			m_RichText.AcceptsTab = true;
			m_RichText.Content.Sections.Clear();

			// Populate the rich text
			PopulateRichText();

			return richTextWithRibbon;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			
			NButton highlightAllChartsButton = new NButton("Highlight All Charts");
			highlightAllChartsButton.Click += OnHighlightAllChartsButtonClick;
			stack.Add(highlightAllChartsButton);

			return stack;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to programmatically create reports as well as how to collect text elements of different type.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text Tables", "https://www.nevron.com/docs/openvision/rich-text-tables.html"), ("Rich Text Paragraphs", "https://www.nevron.com/docs/openvision/rich-text-paragraphs.html"), ("Rich Text Sections", "https://www.nevron.com/docs/openvision/rich-text-sections.html"), ("Rich Text Image Inlines", "https://www.nevron.com/docs/openvision/rich-text-image-inlines.html"), ("Rich Text Field Inlines", "https://www.nevron.com/docs/openvision/rich-text-field-inlines.html"), }; } private void PopulateRichText() { NSection section = new NSection(); m_RichText.Content.Sections.Add(section); NParagraph paragraph = new NParagraph(); paragraph.HorizontalAlignment = ENAlign.Center; paragraph.Inlines.Add(CreateHeaderText("ACME Corporation")); paragraph.Inlines.Add(new NLineBreakInline()); paragraph.Inlines.Add(CreateNormalText("Monthly Health Report")); section.Blocks.Add(paragraph); // generate sample data double[] sales = new double[12]; double[] hours = new double[12]; double[] profitloss = new double[12]; string[] months = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; Random random = new Random(); for (int i = 0; i < 12; i++) { sales[i] = 50 + random.Next(50); hours[i] = 50 + random.Next(50); profitloss[i] = 25 - random.Next(50); } NTable table = new NTable(); section.Blocks.Add(table); table.Columns.Add(new NTableColumn()); table.Columns.Add(new NTableColumn()); { NTableRow tableRow = new NTableRow(); NTableCell tableCell1 = new NTableCell(); NParagraph par1 = new NParagraph(); par1.Inlines.Add(CreateHeaderText("Sales New Projects")); tableCell1.Blocks.Add(par1); tableRow.Cells.Add(tableCell1); NTableCell tableCell2 = new NTableCell(); tableCell2.Blocks.Add(new NParagraph()); tableRow.Cells.Add(tableCell2); table.Rows.Add(tableRow); } { NTableRow tableRow = new NTableRow(); NTableCell tableCell1 = new NTableCell(); NParagraph par1 = new NParagraph(); par1.Inlines.Add(CreateHeaderText("Total Sales: " + GetTotal(sales).ToString())); par1.Inlines.Add(new NLineBreakInline()); par1.Inlines.Add(CreateNormalText("Last Month: " + sales[11].ToString())); tableCell1.Blocks.Add(par1); tableRow.Cells.Add(tableCell1); NTableCell tableCell2 = new NTableCell(); tableCell2.Blocks.Add(CreateBarChart(true, new NSize(400, 200), "Sales", sales, months)); tableRow.Cells.Add(tableCell2); table.Rows.Add(tableRow); } { NTableRow tableRow = new NTableRow(); NTableCell tableCell1 = new NTableCell(); NParagraph par1 = new NParagraph(); par1.Inlines.Add(CreateHeaderText("Billable Hours: " + GetTotal(hours).ToString())); par1.Inlines.Add(new NLineBreakInline()); par1.Inlines.Add(CreateNormalText("Last Month: " + hours[11].ToString())); tableCell1.Blocks.Add(par1); tableRow.Cells.Add(tableCell1); NTableCell tableCell2 = new NTableCell(); tableCell2.Blocks.Add(CreateBarChart(false, new NSize(400, 200), "Hours", hours, months)); tableRow.Cells.Add(tableCell2); table.Rows.Add(tableRow); } { NTableRow tableRow = new NTableRow(); NTableCell tableCell1 = new NTableCell(); NParagraph par1 = new NParagraph(); par1.Inlines.Add(CreateHeaderText("Profit / Loss: " + GetTotal(profitloss).ToString())); par1.Inlines.Add(new NLineBreakInline()); par1.Inlines.Add(CreateNormalText("Last Month: " + profitloss[11].ToString())); tableCell1.Blocks.Add(par1); tableRow.Cells.Add(tableCell1); NTableCell tableCell2 = new NTableCell(); tableCell2.Blocks.Add(CreateBarChart(false, new NSize(400, 200), "Profit / Loss", hours, months)); tableRow.Cells.Add(tableCell2); table.Rows.Add(tableRow); } } #endregion #region Implementation #endregion #region Event Handlers void OnHighlightAllChartsButtonClick(NEventArgs arg) { NList charts = m_RichText.Content.GetDescendants(NChartView.NChartViewSchema); for (int i = 0; i < charts.Count; i++) { NChartView chartView = (NChartView)charts[i]; ((NCartesianChart)chartView.Surface.Charts[0]).PlotFill = new NColorFill(NColor.LightBlue); } } #endregion #region Fields private NRichTextView m_RichText; #endregion #region Static Methods private static double GetTotal(double[] values) { double total = 0.0; for (int i = 0; i < values.Length; i++) { total += values[i]; } return total; } private static NTextInline CreateHeaderText(string text) { NTextInline inline = new NTextInline(text); inline.FontSize = 14; inline.FontStyle = ENFontStyle.Bold; return inline; } private static NTextInline CreateNormalText(string text) { NTextInline inline = new NTextInline(text); inline.FontSize = 9; return inline; } /// /// Creates a sample bar chart given title, values and labels /// /// /// /// /// /// /// private static NParagraph CreateBarChart(bool area, NSize size, string title, double[] values, string[] labels) { NChartView chartView = new NChartView(); chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian); chartView.PreferredSize = size; // configure title chartView.Surface.Titles[0].Text = title; chartView.Surface.Titles[0].Margins = NMargins.Zero; chartView.Surface.Legends[0].Visibility = ENVisibility.Hidden; chartView.BorderThickness = NMargins.Zero; // configure chart NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0]; chart.Padding = new NMargins(20); chart.Margins = NMargins.Zero; if (area) { NAreaSeries areaSeries = new NAreaSeries(); areaSeries.LegendView.Mode = ENSeriesLegendMode.None; areaSeries.DataLabelStyle = new NDataLabelStyle(false); chart.Series.Add(areaSeries); for (int i = 0; i < values.Length; i++) { areaSeries.DataPoints.Add(new NAreaDataPoint(values[i])); } } else { NBarSeries barSeries = new NBarSeries(); barSeries.LegendView.Mode = ENSeriesLegendMode.None; barSeries.DataLabelStyle = new NDataLabelStyle(false); chart.Series.Add(barSeries); for (int i = 0; i < values.Length; i++) { barSeries.DataPoints.Add(new NBarDataPoint(values[i])); } } NOrdinalScale scaleX = (NOrdinalScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale; scaleX.Labels.TextProvider = new NOrdinalScaleLabelTextProvider(labels); scaleX.MajorTickMode = ENMajorTickMode.CustomStep; scaleX.CustomStep = 1; NParagraph paragraph = new NParagraph(); NWidgetInline chartInline = new NWidgetInline(); chartInline.Content = chartView; paragraph.Inlines.Add(chartInline); return paragraph; } #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Report 2 Example for Blazor Solution