Skip to content

Instantly share code, notes, and snippets.

@Tempest1000
Created December 20, 2019 21:02
Show Gist options
  • Save Tempest1000/bfcf8dd09e27f2ae7cd68ac068724516 to your computer and use it in GitHub Desktop.
Save Tempest1000/bfcf8dd09e27f2ae7cd68ac068724516 to your computer and use it in GitHub Desktop.
<Query Kind="Program">
<Namespace>System.Globalization</Namespace>
</Query>
void Main()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); //Separate double digits with dot not comma - please!
var data = new[] {22.61, 22.59, 22.63, 22.60, 22.62, 22.58, 22.61, 22.62, 22.60, 22.64, 22.69, 22.62, 22.65, 22.62, 22.61, 22.65, 22.63, 22.61, 22.65, 22.63, 22.59, 22.62, 22.59, 22.64, 22.58, 22.61, 22.63, 22.61, 22.61, 22.69, 22.62, 22.59, 22.65, 22.65, 22.64, 22.63, 22.63, 22.63, 22.59, 22.61, 22.67, 22.57, 22.60, 22.61, 22.61, 22.61, 22.60, 22.61, 22.64, 22.62, 22.63, 22.67, 22.65, 22.65, 22.61, 22.63, 22.63, 22.61, 22.62, 22.69, 22.62, 22.59, 22.59, 22.61, 22.61, 22.58, 22.61, 22.65, 22.61, 22.63, 22.68, 22.62, 22.64, 22.62, 22.62, 22.64, 22.64, 22.63, 22.65, 22.61, 22.60, 22.63, 22.59, 22.62, 22.61, 22.59, 22.63, 22.62, 22.60, 22.69, 22.62, 22.61, 22.63, 22.65, 22.64, 22.63, 22.63, 22.65, 22.58, 22.60};
RenderLineGraph("Time", "P1", data);
}
public void RenderLineGraph(string horizontalAxisName, string verticalAxisName, IEnumerable<double> data)
{
// Credit to some unknown source on the internet.
// I've seen examples like this on both Twitter and StackOverflow for people using LINQPad in creative ways.
// This is a great example of using the Util function to output HTML that LINQPad renders in results.
// This could be used in interesting ways to graph data from JIRA retrieved via API call for instance.
var i = 0;
var jsData = "[" + string.Join(", ", data.Select(d => $"[{i++}, {d}]")) + "]";
Util.RawHtml($@"
<html>
<body>
<script type=""text/javascript"" src=""https://www.gstatic.com/charts/loader.js""></script>
<div id=""chart_div""></div>
<script>
google.charts.load('current', {{packages: ['corechart', 'line']}});
google.charts.setOnLoadCallback(drawBasic);
function drawBasic() {{
var data = new google.visualization.DataTable();
data.addColumn('number', 'X');
data.addColumn('number', '{verticalAxisName}');
data.addRows({jsData});
var options = {{
hAxis: {{
title: '{horizontalAxisName}'
}},
vAxis: {{
title: '{verticalAxisName}'
}}
}};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}}
</script>
</body>
</html>
").Dump();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment