Skip to content

Commit ee32634

Browse files
committed
feat(chart):added demo project for printing only chart
1 parent 1a14881 commit ee32634

33 files changed

+1367
-0
lines changed

Diff for: chart/print-chart-only/print-chart.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30709.64
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "print-chart", "print-chart\print-chart.csproj", "{EAE6D560-6F7E-443F-A71F-B4E476FE39F3}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{EAE6D560-6F7E-443F-A71F-B4E476FE39F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EAE6D560-6F7E-443F-A71F-B4E476FE39F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EAE6D560-6F7E-443F-A71F-B4E476FE39F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EAE6D560-6F7E-443F-A71F-B4E476FE39F3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {55A7FE59-C30F-494E-8626-E30DABB250C6}
24+
EndGlobalSection
25+
EndGlobal

Diff for: chart/print-chart-only/print-chart/App.razor

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<h1>Page not found</h1>
7+
<p>Sorry, but there's nothing here!</p>
8+
</NotFound>
9+
</Router>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@inject IJSRuntime JSRuntime
2+
3+
<div class="chart-container @(isPrinting ? "" : "non-printable-chart")">
4+
<TelerikButton OnClick="@Print" Icon="@IconName.Print" Class="print-button">Print this chart</TelerikButton>
5+
6+
<TelerikChart Width="700px" Height="400px">
7+
<ChartSeriesItems>
8+
<ChartSeries Type="@seriesType" Name="Product 1" Data="@series1Data">
9+
</ChartSeries>
10+
<ChartSeries Type="@seriesType" Name="Product 2" Data="@series2Data">
11+
</ChartSeries>
12+
</ChartSeriesItems>
13+
14+
<ChartCategoryAxes>
15+
<ChartCategoryAxis Categories="@xAxisItems"></ChartCategoryAxis>
16+
</ChartCategoryAxes>
17+
18+
<ChartTitle Text="Quarterly revenue per product"></ChartTitle>
19+
20+
<ChartLegend Position="@ChartLegendPosition.Right">
21+
</ChartLegend>
22+
</TelerikChart>
23+
</div>
24+
25+
@code {
26+
[Parameter]
27+
public ChartSeriesType seriesType { get; set; }
28+
[Parameter]
29+
public EventCallback<ChartSeriesType> seriesTypeChanged { get; set; }
30+
31+
32+
bool isPrinting { get; set; }
33+
34+
35+
async Task Print()
36+
{
37+
isPrinting = true;
38+
await InvokeAsync(StateHasChanged);
39+
await Task.Delay(20);
40+
await JSRuntime.InvokeVoidAsync("print");
41+
isPrinting = false;
42+
}
43+
44+
public List<object> series1Data = new List<object>() { 10, 2, 5, 6 };
45+
public List<object> series2Data = new List<object>() { 5, 8, 2, 7 };
46+
public string[] xAxisItems = new string[] { "Q1", "Q2", "Q3", "Q4" };
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace PrintingCharts.Data
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
5+
namespace PrintingCharts.Data
6+
{
7+
public class WeatherForecastService
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
15+
{
16+
var rng = new Random();
17+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
18+
{
19+
Date = startDate.AddDays(index),
20+
TemperatureC = rng.Next(-20, 55),
21+
Summary = Summaries[rng.Next(Summaries.Length)]
22+
}).ToArray());
23+
}
24+
}
25+
}

Diff for: chart/print-chart-only/print-chart/Pages/Index.razor

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@page "/"
2+
@using PrintChartOnly.Components
3+
4+
<PrintableChart @bind-seriesType="@series1Type" />
5+
<PrintableChart @bind-seriesType="@series2Type" />
6+
<PrintableChart @bind-seriesType="@series3Type" />
7+
8+
9+
@code {
10+
ChartSeriesType series1Type = ChartSeriesType.Bar;
11+
ChartSeriesType series2Type = ChartSeriesType.Line;
12+
ChartSeriesType series3Type = ChartSeriesType.Area;
13+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@page "/"
2+
@namespace PrintingCharts.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10+
<title>PrintingCharts</title>
11+
<base href="~/" />
12+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
13+
<link href="css/site.css" rel="stylesheet" />
14+
<link rel="stylesheet" href="_content/Telerik.UI.for.Blazor/css/kendo-theme-default/all.css" />
15+
<link href="css/printingStyles.css" media="print" rel="stylesheet" />
16+
<link href="css/printButtonStyles.css" rel="stylesheet" />
17+
<script src="_content/Telerik.UI.for.Blazor/js/telerik-blazor.js" defer></script>
18+
</head>
19+
<body>
20+
<component type="typeof(App)" render-mode="ServerPrerendered" />
21+
22+
<div id="blazor-error-ui">
23+
<environment include="Staging,Production">
24+
An error has occurred. This application may no longer respond until reloaded.
25+
</environment>
26+
<environment include="Development">
27+
An unhandled exception has occurred. See browser dev tools for details.
28+
</environment>
29+
<a href class="reload">Reload</a>
30+
<a class="dismiss">🗙</a>
31+
</div>
32+
33+
<script src="_framework/blazor.server.js"></script>
34+
</body>
35+
</html>

Diff for: chart/print-chart-only/print-chart/Program.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.AspNetCore;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.Hosting;
5+
using Microsoft.Extensions.Logging;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Threading.Tasks;
11+
12+
namespace PrintChartOnly
13+
{
14+
public class Program
15+
{
16+
public static void Main(string[] args)
17+
{
18+
CreateHostBuilder(args).Build().Run();
19+
}
20+
21+
public static IHostBuilder CreateHostBuilder(string[] args) =>
22+
Host.CreateDefaultBuilder(args)
23+
.ConfigureWebHostDefaults(webBuilder =>
24+
{
25+
webBuilder.UseStaticWebAssets();
26+
webBuilder.UseStartup<Startup>();
27+
});
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:55276/",
7+
"sslPort": 44398
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"PrintingCharts": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
25+
}
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@layout TelerikLayout
2+
3+
@inherits LayoutComponentBase
4+
5+
<div class="page">
6+
<div class="sidebar">
7+
<NavMenu />
8+
</div>
9+
10+
<div class="main">
11+
<div class="top-row px-4">
12+
<a href="https://docs.microsoft.com/en-us/aspnet/" target="_blank">About</a>
13+
</div>
14+
15+
<div class="content px-4">
16+
@Body
17+
</div>
18+
</div>
19+
</div>
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">PrintingCharts</a>
3+
<button class="navbar-toggler" @onclick="ToggleNavMenu">
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
12+
<span class="oi oi-home" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
</ul>
16+
</div>
17+
18+
@code {
19+
bool collapseNavMenu = true;
20+
21+
string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
22+
23+
void ToggleNavMenu()
24+
{
25+
collapseNavMenu = !collapseNavMenu;
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@inherits LayoutComponentBase
2+
3+
<TelerikRootComponent>
4+
@Body
5+
</TelerikRootComponent>

Diff for: chart/print-chart-only/print-chart/Startup.cs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Components;
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.AspNetCore.HttpsPolicy;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Hosting;
8+
using PrintingCharts.Data;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Threading.Tasks;
13+
14+
namespace PrintChartOnly
15+
{
16+
public class Startup
17+
{
18+
public Startup(IConfiguration configuration)
19+
{
20+
Configuration = configuration;
21+
}
22+
23+
public IConfiguration Configuration { get; }
24+
25+
// This method gets called by the runtime. Use this method to add services to the container.
26+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
27+
public void ConfigureServices(IServiceCollection services)
28+
{
29+
services.AddRazorPages();
30+
services.AddServerSideBlazor();
31+
services.AddTelerikBlazor();
32+
services.AddSingleton<WeatherForecastService>();
33+
}
34+
35+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
36+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
37+
{
38+
if (env.IsDevelopment())
39+
{
40+
app.UseDeveloperExceptionPage();
41+
}
42+
else
43+
{
44+
app.UseExceptionHandler("/Error");
45+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
46+
app.UseHsts();
47+
}
48+
49+
app.UseHttpsRedirection();
50+
app.UseStaticFiles();
51+
52+
app.UseRouting();
53+
54+
app.UseEndpoints(endpoints =>
55+
{
56+
endpoints.MapDefaultControllerRoute();
57+
endpoints.MapControllers();
58+
59+
endpoints.MapBlazorHub();
60+
endpoints.MapFallbackToPage("/_Host");
61+
});
62+
}
63+
}
64+
}

Diff for: chart/print-chart-only/print-chart/_Imports.razor

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@using System.Net.Http
2+
@using Microsoft.AspNetCore.Authorization
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Authorization
6+
@using Microsoft.AspNetCore.Components.Web
7+
@using Microsoft.JSInterop
8+
@using PrintChartOnly
9+
@using PrintChartOnly.Shared
10+
@using Telerik.Blazor
11+
@using Telerik.Blazor.Components
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
}
9+
}

Diff for: chart/print-chart-only/print-chart/appsettings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*"
10+
}

0 commit comments

Comments
 (0)