#region Setup using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using ChartForgeX.Core; using ChartForgeX.Primitives; using ChartForgeX.Rendering; using ChartForgeX.Themes; using ChartForgeX.Topology; using ChartForgeX.Typography; using ChartForgeX.VisualArtifacts; using ChartForgeX.VisualBlocks; var mode = VisualThemeMode.Light; 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)); 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", VisualThemeMode mode = VisualThemeMode.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().WithLegend(false).WithDataLabels().WithXLabels(stages.Select(stage => stage.Name).ToArray()) .AddSeries(series).ConfigureFunnel(options => { options.Form = ChartFunnelForm.Cone; // Stage names and retention sit beside the cone, so narrow stages keep their full captions. options.LabelContent = ChartStageLabelContent.Separate; }); } }