Example of RTL in ASP.NET Core Charts Control
This sample visualizes a company’s performance with a default column chart rendered right-to-left (RTL). The values of the data points are displayed in a tooltip and the legend in the sample displays information about the series.
@* The chart's settings are in the view; the data they read (ViewData) is set in the controller action (see the controller tab). *@
@Html.UiChart(new UiChartOptions
{
Id = "rtlChart",
Title = "Company Performance",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ShowGridLines = false, Interval = 1, Minimum = 2015, Maximum = 2020, ValueType = UiChartValueType.Double },
PrimaryYAxis = new UiChartAxis { Minimum = 0, LabelFormat = "{value}B", Maximum = 1200, Interval = 200 },
EnableRtl = true,
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Column, Width = 2, XName = "Year", YName = "Sales", Name = "Sales", ColumnSpacing = 0.1 },
new UiChartSeries { Type = UiChartSeriesType.Column, Width = 2, XName = "Year", YName = "Expense", Name = "Expense", ColumnSpacing = 0.1 },
new UiChartSeries { Type = UiChartSeriesType.Column, Width = 2, XName = "Year", YName = "Profit", Name = "Profit", ColumnSpacing = 0.1 }
}
})
@Html.UiChart(new UiChartOptions
{
Id = "rtlChart",
Title = "Company Performance",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true },
Legend = new UiChartLegend { EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { ShowGridLines = false, Interval = 1, Minimum = 2015, Maximum = 2020, ValueType = UiChartValueType.Double },
PrimaryYAxis = new UiChartAxis { Minimum = 0, LabelFormat = "{value}B", Maximum = 1200, Interval = 200 },
EnableRtl = true,
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Column, Width = 2, XName = "Year", YName = "Sales", Name = "Sales", ColumnSpacing = 0.1 },
new UiChartSeries { Type = UiChartSeriesType.Column, Width = 2, XName = "Year", YName = "Expense", Name = "Expense", ColumnSpacing = 0.1 },
new UiChartSeries { Type = UiChartSeriesType.Column, Width = 2, XName = "Year", YName = "Profit", Name = "Profit", ColumnSpacing = 0.1 }
}
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ChartController : Controller
{
// The page is Views/Chart/ChartRtl.cshtml; it draws what ViewData holds.
public ActionResult ChartRtl()
{
List<RTLData> ChartPoints = new List<RTLData>
{
new RTLData { Year = 2016, Sales = 1000, Expense = 400, Profit = 600 },
new RTLData { Year = 2017, Sales = 970, Expense = 360, Profit = 610 },
new RTLData { Year = 2018, Sales = 1060, Expense = 920, Profit = 140 },
new RTLData { Year = 2019, Sales = 1030, Expense = 540, Profit = 490 }
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class RTLData
{
public double Year { get; set; }
public double Sales { get; set; }
public double Expense { get; set; }
public double Profit { get; set; }
}
}
}
@* Program.cs *@
builder.Services.AddControllersWithViews().AddLumenUIJson();
builder.Services.AddLumenUI();
// ...
app.UseLumenUI();
@* Views/_ViewImports.cshtml *@
@using Lumen.UI.Mvc
@addTagHelper *, Lumen.UI.Core
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@await RenderSectionAsync("scripts", required: false)
</body>
@* Charts with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
Right-to-left(RTL) is used to render a component from right to left (RTL) and it can be enabled by setting the EnableRtl property as true. In this demo, you can see the Axis, Data Points, Tooltip and Legend are aligned from right to left.
Tooltip is enabled in this example. To see the tooltip in action, hover over a point or tap on a point in touch-enabled devices.