Chart

TsgcHTMLComponent_Chart — render Chart.js graphs (line, bar, pie, doughnut, radar, polar, bubble and scatter) from your own data or directly from a dataset, in Delphi, C++ Builder and .NET.

TsgcHTMLComponent_Chart

A charting component that emits a Chart.js <canvas> plus its configuration script. Set the type, add labels and datasets, then read the HTML property.

Component class

TsgcHTMLComponent_Chart

Renders

Chart.js <canvas> + Bootstrap 5 markup

Languages

Delphi, C++ Builder, .NET

Create it, add data, render it

Set ChartType, push labels and one or more datasets, then read HTML (or drop it into a TsgcHTMLTemplate_Bootstrap page).

uses
  sgcHTML_Enums, sgcHTML_Component_Chart;

var
  oChart: TsgcHTMLComponent_Chart;
begin
  oChart := TsgcHTMLComponent_Chart.Create(nil);
  try
    oChart.ChartType := ctBar;
    oChart.Title := 'Quarterly Revenue';
    oChart.Height := '320';

    oChart.AddLabel('Q1');
    oChart.AddLabel('Q2');
    oChart.AddLabel('Q3');

    oChart.AddDataset('Revenue', [1200, 1900, 1500],
      '#7C3AED', 'rgba(124,58,237,.25)', True);

    WebModule.Response := oChart.HTML;   // <canvas> + Chart.js script
  finally
    oChart.Free;
  end;
end;

// Or bind it straight to a dataset:
oChart.LoadFromDataSet(qryQuarters, 'Quarter', 'Revenue');
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Chart.hpp

TsgcHTMLComponent_Chart *oChart = new TsgcHTMLComponent_Chart(NULL);
try
{
  oChart->ChartType = ctBar;
  oChart->Title = "Quarterly Revenue";
  oChart->Height = "320";

  oChart->AddLabel("Q1");
  oChart->AddLabel("Q2");
  oChart->AddLabel("Q3");

  oChart->AddDataset("Revenue", OPENARRAY(double, (1200, 1900, 1500)),
    "#7C3AED", "rgba(124,58,237,.25)", true);

  String html = oChart->HTML;   // <canvas> + Chart.js script
}
__finally
{
  delete oChart;
}
using esegece.sgcWebSockets;

var chart = new TsgcHTMLComponent_Chart();
chart.ChartType = TsgcHTMLChartType.ctBar;
chart.Title = "Quarterly Revenue";
chart.Height = "320";

chart.AddLabel("Q1");
chart.AddLabel("Q2");
chart.AddLabel("Q3");

chart.AddDataset("Revenue", new double[] { 1200, 1900, 1500 },
    "#7C3AED", "rgba(124,58,237,.25)", true);

string html = chart.HTML;   // <canvas> + Chart.js script

Key properties & methods

The members you reach for most often.

Chart type

ChartType selects line, bar, pie, doughnut, radar, polar, bubble or scatter; Stacked stacks datasets; Title sets the heading.

Data

AddLabel adds an axis label; AddDataset(label, data, color, bgColor, fill) adds a series; ClearData resets it; Datasets and Labels expose the collections.

Dataset binding

LoadFromDataSet(aDataSet, aLabelField, aValueFields) fills the chart from a query; assign DataSource for live refresh.

Appearance

Width, Height, ShowLegend, Responsive, PointRadius and CustomOptions (raw Chart.js options JSON) tune the look.

Output

HTML returns the <canvas> plus its Chart.js configuration script — serve it, or assign it to a page template's BodyContent.

Layout

Inherited Section, ColumnWidth and RowGroup place the chart on a TsgcHTMLPageBuilder grid.

Keep exploring

All sgcHTML ComponentsBrowse the full feature matrix of 60+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.

Ready to Get Started?

Download the free trial and start building web UIs in Delphi, C++ Builder and .NET.