Skip to content

Instantly share code, notes, and snippets.

@bhavika
Last active June 26, 2021 21:41
Show Gist options
  • Save bhavika/fa653c388004c6a73eb5 to your computer and use it in GitHub Desktop.
Save bhavika/fa653c388004c6a73eb5 to your computer and use it in GitHub Desktop.
Creating a stacked bar graph in C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Helpers;
using System.Web.Mvc;
using System.Web.UI;
public class StackedBarGraph
{
public ActionResult CreateStackedBarGraph()
{
//Using Web Helpers Chart methods
// chartType: StackedBar, StackedColumn, etc
//Writing this because no documentation or code samples on how to pass multiple values for x and y exist
var key = new Chart(width: 300, height: 200, theme: ChartTheme.Green).AddTitle("Stacked bar demo")
.AddSeries
(
chartType: "StackedBar",
legend: "Item1",
xValue: new[] { "2012", "2013", "2014", "2015"},
yValues: new [] {34, 50, 10, 25}
)
.AddSeries(
chartType:"StackedBar",
xValue: new[] { "2012", "2013", "2014", "2015" },
yValues: new [] {12,54,85,3}
)
.AddSeries(chartType: "StackedBar",
xValue: new[] {"2012", "2013", "2014", "2015"},
yValues: new [] {15, 5, 74, 32}
);
return File(key.ToWebImage().GetBytes(), "image/jpeg");
}
}
}
@ripollete
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment