#region Setup using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using ChartForgeX; using ChartForgeX.Core; using ChartForgeX.Primitives; using ChartForgeX.Rendering; using ChartForgeX.Themes; using ChartForgeX.Topology; using ChartForgeX.Typography; using ChartForgeX.VisualArtifacts; using ChartForgeX.VisualBlocks; // Native PNG and standalone SVG use bundled Archivo. // Add ChartFontAssets.StyleSheet once for other text on a host page. var mode = ThemeMode.Dark; var theme = VisualTheme.Graphite(); var model = ConeFunnelRecipe.Create("wide", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(800, 480)), theme, mode, new VisualFrame("From visitor to renewed subscription", "Each stage narrows the cone by the customers it keeps", showLegend: null, showSurface: false), FontSpec.FromFamily(ChartFontStacks.ProductSans)); var prepared = model.Prepare(context); File.WriteAllText("visual.svg", prepared.ToSvg()); File.WriteAllBytes("visual.png", prepared.ToPng()); File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Chart).ToHtmlPage()); #endregion /// A cone funnel: trial sign-ups narrowing to renewed subscriptions, with retention captions. public static class ConeFunnelRecipe { public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) { if (variant is not ("wide" or "compact")) throw new ArgumentOutOfRangeException(nameof(variant)); var stages = new (string Name, double Count)[] { ("Visitors", 12400), ("Sign-ups", 5270), ("Trials", 2130), ("Paid", 860), ("Renewed", 610) }; var series = new ChartSeries(new ChartSeriesId("customers"), "Customers", ChartSeriesKind.Funnel, stages.Select((stage, index) => new ChartPoint(index + 1, stage.Count))); return Chart.Create().Legend(false).DataLabels().XLabels(stages.Select(stage => stage.Name).ToArray()) .AddSeries(series).Funnel(options => { options.Form = ChartFunnelForm.Cone; // Stage names and retention sit beside the cone, so narrow stages keep their full captions. options.LabelContent = ChartStageLabelContent.Separate; }); } }