Skip to content

Commit

Permalink
Gantt Charts and Google Chart namespace
Browse files Browse the repository at this point in the history
Added support for Gantt chart and started using the google.chart
namespace rather then the older google.load('visualization'...).
  • Loading branch information
JulsMan committed Jan 20, 2016
1 parent d403b5d commit e6f18ea
Show file tree
Hide file tree
Showing 37 changed files with 185 additions and 179 deletions.
Binary file added .vs/GoogleChartsNGraphsControls/v14/.suo
Binary file not shown.
175 changes: 28 additions & 147 deletions GoogleChartsNGraphsControls/BaseGVI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum GOOGLECHART
WORDCLOUD, SCATTERCHART, TABLEARROW, TABLEBAR,
CANDLESTICK, COMBO, HISTOGRAM, DONUT, TREEMAP,
TIMELINE, WORDTREE, CALENDAR, ANNOTATION, SANKEY,

GANTT,
CHAP_TIMELINE, CHAP_GRAPH, CHAP_GRAPH3D, CHAP_NETWORK
}

Expand All @@ -39,82 +39,6 @@ public enum GOOGLECHART
/// easily debugged or matching that on the Google Vis site
/// </summary>

private static string jschap =
@"
/********************************************************************************
* GoogleVisualizationControls.NET {{ver}}
* http://code.google.com/p/googlevisualizationsdotnet/
* Visualization: {3}
* Div Element: {0}
*********************************************************************************/
google.load('visualization', '1');
google.setOnLoadCallback( draw_{0} );
var chart_{0} = undefined;
function draw_{0}() {{
var container = document.getElementById('{0}');
var chart = new links.{3}(container);
var arrayD = __DATATABLE__;
var data = new google.visualization.DataTable( arrayD );
/********* Formatter Hooks: your function will be called before render ********/
chart.formatters = function(chart,data){{
/*FORMATTERS*/
}}
/********* View Hooks: DataTables are placed in a View and invoke your functions before going to render ********/
chart.formatView = function(chart,view){{
/*VIEW_FUNCTIONS*/
}}
/********* Extended Functions **********************/
chart.reload = function(args, url)
{{
if (url == undefined || url == null){{
url = '{QueryString}';
}}
m_SendAndDraw(container, chart, url, args)
}};
chart.load = function(data)
{{
m_JustDraw(container, chart, data);
}};
chart.format = function(data)
{{
{formatter}
}};
/********* User Defined Functions **********************/
{4}
/********* Extended Params **********************/
chart.opts = {1};
chart.container = container;
/********* Init Chart Load **********************/
chart.draw(data, chart.opts);
/********* Update These Image Src **********************/
{SETIMAGEFOR}
/********* Save Chart Into DOM / Always Last **********************/
chart_{0} = chart;
}}
";

private static string jscode3 =
@"
Expand All @@ -125,12 +49,27 @@ public enum GOOGLECHART
* Visualization: {3}
* Div Element: {0}
*********************************************************************************/
/*
google.load('visualization', '1', {{ 'packages': ['{2}'] }});
google.setOnLoadCallback( draw_{0} );
*/
/* google.charts.load('current', {{'packages':['{2}']}} ); */
google.charts.setOnLoadCallback( draw_{0} );
var chart_{0} = undefined;
function draw_{0}() {{
var container = document.getElementById('{0}');
var chart = new google.visualization.{3}(container);
var chart = undefined;
if (google.visualization.{3} == undefined)
{{
chart = new google.visualization.{5}(container);
}}
else
{{
chart = new google.visualization.{3}(container);
}}
var data = __DATATABLE__;
Expand Down Expand Up @@ -191,71 +130,6 @@ public enum GOOGLECHART
";


// private static string jscode =
// @"
//
// /********************************************************************************
// * GoogleVisualizationControls for .NET - by Julian King
// * Visualization: {3}
// * Div Element: {0}
// *********************************************************************************/
// google.load('visualization', '1', {{ 'packages': ['{2}'] }});
// google.setOnLoadCallback(draw_{0});
// function draw_{0}() {{
// var data = new google.visualization.DataTable(chart_{0});
// var chart = new google.visualization.{3}(document.getElementById('{0}'));
// chart.draw(data, {1});
// }}
//";

// private static string jscode2 =
// @"
//
// /********************************************************************************
// * GoogleVisualizationControls.NET {{ver}}
// * http://code.google.com/p/googlevisualizationsdotnet/
// * Visualization: {3}
// * Div Element: {0}
// *********************************************************************************/
// var chart_{0} = undefined;
// google.load('visualization', '1', {{ 'packages': ['{2}'] }});
// google.setOnLoadCallback( draw_{0} );
// var regEvts_{0} = function(chart) {{
// {4}
// }};
// function draw_{0}() {{
// var data = data_{0}();
// var chart = new google.visualization.{3}(document.getElementById('{0}'));
// regEvts_{0}(chart);
// chart.draw(data, {1});
// chart_{0} = chart;
// }}
//";





// private static string jscode_orig =
// @"
//
// /********************************************************************************
// * GoogleVisualizationControls for .NET - by Julian King
// * Visualization: {3}
// * Div Element: {0}
// *********************************************************************************/
// google.load('visualization', '1', {{ 'packages': ['{2}'] }});
// google.setOnLoadCallback(draw_{0});
// var regEvts_{0} = function(chart) {{
// {4}
// }};
// function draw_{0}() {{
// var data = chart_{0}();
// var chart = new google.visualization.{3}(document.getElementById('{0}'));
// regEvts_{0}(chart);
// chart.draw(data, {1});
// }}
//";
#endregion

private static readonly Dictionary<GOOGLECHART, string[]> dic = new Dictionary<GOOGLECHART, string[]>();
Expand All @@ -275,7 +149,7 @@ public BaseGVI()
dic.Add(GOOGLECHART.MOTIONCHART, new string[] { "motionchart", "MotionChart" });
dic.Add(GOOGLECHART.ORGANIZATIONCHART, new string[] { "orgchart", "OrgChart" });
dic.Add(GOOGLECHART.PIECHART, new string[] { "corechart", "PieChart" });
//dic.Add(GOOGLECHART.SPARKLINE, new string[] { "imagesparkline", "ImageSparkLine" });
dic.Add(GOOGLECHART.GANTT, new string[] { "gantt", "gantt" });
dic.Add(GOOGLECHART.SCATTERCHART, new string[] { "corechart", "ScatterChart" });
dic.Add(GOOGLECHART.TABLEARROW, new string[] { "table", "Table" });
dic.Add(GOOGLECHART.TABLEBAR, new string[] { "table", "Table" });
Expand Down Expand Up @@ -309,8 +183,8 @@ internal void RegisterGVIScriptsEx(BaseWebControl PageControl, DataTable dt, GOO
{
string JAVASCRIPT = jscode3;

if (CHARTTYPE == GOOGLECHART.CHAP_TIMELINE)
JAVASCRIPT = jschap;
//if (CHARTTYPE == GOOGLECHART.CHAP_TIMELINE)
// JAVASCRIPT = jschap;

string options,formatter = string.Empty;
string imagereplace = string.Empty;
Expand Down Expand Up @@ -357,7 +231,14 @@ internal void RegisterGVIScriptsEx(BaseWebControl PageControl, DataTable dt, GOO
ctlid = PageControl.OverrideElementId;

// interpolate the options into the canned Javascript
string optionsJscode = string.Format(JAVASCRIPT, ctlid, options, dic[CHARTTYPE].FirstOrDefault(), dic[CHARTTYPE].LastOrDefault(), string.Join("\n",events.ToArray()));
string optionsJscode = string.Format(JAVASCRIPT,
ctlid,
options,
dic[CHARTTYPE].FirstOrDefault(),
dic[CHARTTYPE].LastOrDefault(),
string.Join("\n",events.ToArray()),
dic[CHARTTYPE].FirstOrDefault().UpperCaseFirst()
);

// add version information onto each ChartJavascript
string build = string.Format("v{0}.{1}.{2}.{3}",
Expand Down
9 changes: 9 additions & 0 deletions GoogleChartsNGraphsControls/BaseWebControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,15 @@ protected override void OnLoad(EventArgs e)
if (!this.Page.ClientScript.IsClientScriptIncludeRegistered("REGISTER_GOOGLE_API_JS"))
this.Page.ClientScript.RegisterClientScriptInclude("REGISTER_GOOGLE_API_JS", "https://www.google.com/jsapi");

if (!this.Page.ClientScript.IsClientScriptIncludeRegistered("REGISTER_GOOGLE_LOADER"))
this.Page.ClientScript.RegisterClientScriptInclude("REGISTER_GOOGLE_LOADER", "https://www.gstatic.com/charts/loader.js");

if (!this.Page.ClientScript.IsClientScriptBlockRegistered(this.GetType().BaseType, "REGISTER_GOOGLE_PACKAGES"))
{
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType().BaseType, "REGISTER_GOOGLE_PACKAGES",
"google.charts.load('current', {'packages':['corechart','gantt', 'map','annotatedtimeline','gauge','table','timeline','annotationchart', 'calendar','motionchart','orgchart']});", true);
}

if (!this.Page.ClientScript.IsClientScriptBlockRegistered(this.GetType().BaseType, "REGISTER_JX_AJAX"))
{
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType().BaseType, "REGISTER_JX_AJAX",
Expand Down
5 changes: 4 additions & 1 deletion GoogleChartsNGraphsControls/DataStructs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ public static string LowerCaseFirst(this string str)
{
return char.ToLower(str[0]) + str.Substring(1);
}

public static string UpperCaseFirst(this string str)
{
return char.ToUpper(str[0]) + str.Substring(1).ToLower();
}
public static string GVINameParse(this string str)
{
if (str.StartsWith("Gvi", true, System.Globalization.CultureInfo.CurrentCulture))
Expand Down
42 changes: 18 additions & 24 deletions GoogleChartsNGraphsControls/GVGanttChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ public class GVGanttChart : BaseWebControl, IsStackable

protected override void RenderContents(HtmlTextWriter output)
{
List<Color?> tmp = new List<Color?>();
tmp.Add(this.GVIBackgroundColor == null ? Color.Transparent : this.GVIBackgroundColor);
if (this.GviColors != null) tmp.AddRange(this.GviColors);

this.GviIsStacked = true;
this.GviColors = tmp.ToArray();
this.GviTitle = string.IsNullOrEmpty(this.GviTitle) ? this.dt.TableName : this.GviTitle;
this.gvi.RegisterGVIScriptsEx(this, TableWithLeadTime(this.dt), BaseGVI.GOOGLECHART.BARCHART);
this.gvi.RegisterGVIScriptsEx(this, this.dt, BaseGVI.GOOGLECHART.GANTT);
output.Write(Text);
}
// Support for IPostBackEventHandler
Expand Down Expand Up @@ -85,27 +79,27 @@ protected override void RenderContents(HtmlTextWriter output)
* So our Gantt chart now starts to give us some more detailed information.
* We’ll also add some data labels so a legend is painted.
*/
internal static System.Data.DataTable TableWithLeadTime(System.Data.DataTable dt)
{
if (dt.Columns.Count > 2) throw new Exception("Gantt Charts don't support having more then 2 columns valid ie.['Date',value]");
//internal static System.Data.DataTable TableWithLeadTime(System.Data.DataTable dt)
//{
// if (dt.Columns.Count > 2) throw new Exception("Gantt Charts don't support having more then 2 columns valid ie.['Date',value]");

// test for numeric types only
// // test for numeric types only

System.Data.DataTable dtwithlead = new System.Data.DataTable();
dtwithlead.Columns.Add(dt.Columns[0].ColumnName, dt.Columns[0].DataType);
dtwithlead.Columns.Add(" ",dt.Columns[1].DataType);
dtwithlead.Columns.Add(dt.Columns[1].ColumnName, dt.Columns[1].DataType);
// System.Data.DataTable dtwithlead = new System.Data.DataTable();
// dtwithlead.Columns.Add(dt.Columns[0].ColumnName, dt.Columns[0].DataType);
// dtwithlead.Columns.Add(" ",dt.Columns[1].DataType);
// dtwithlead.Columns.Add(dt.Columns[1].ColumnName, dt.Columns[1].DataType);

int leading = 0;
foreach(System.Data.DataRow dr in dt.Rows)
{
object[] tmp = new object[]{dr[0],leading,dr[1]};
leading += int.Parse(dr[1].ToString());
dtwithlead.Rows.Add(tmp);
}
// int leading = 0;
// foreach(System.Data.DataRow dr in dt.Rows)
// {
// object[] tmp = new object[]{dr[0],leading,dr[1]};
// leading += int.Parse(dr[1].ToString());
// dtwithlead.Rows.Add(tmp);
// }

return dtwithlead;
}
// return dtwithlead;
//}

public override string ToString()
{
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified GoogleChartsNGraphsControls/bin/Debug/Visualization.dll
Binary file not shown.
Binary file modified GoogleChartsNGraphsControls/bin/Debug/Visualization.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ C:\Users\kingj5\Documents\Visual Studio 2010\Projects\googlevisualizationsdotnet
C:\Users\kingj5\Documents\Visual Studio 2010\Projects\googlevisualizationsdotnet\GoogleChartsNGraphsControls\obj\Debug\GoogleChartsNGraphsControls.csproj.GenerateResource.Cache
C:\Users\kingj5\Documents\Visual Studio 2010\Projects\googlevisualizationsdotnet\GoogleChartsNGraphsControls\obj\Debug\GoogleChartsNGraphsControls.dll
C:\Users\kingj5\Documents\Visual Studio 2010\Projects\googlevisualizationsdotnet\GoogleChartsNGraphsControls\obj\Debug\GoogleChartsNGraphsControls.pdb
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\bin\Debug\GoogleChartsNGraphsControls.dll
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\bin\Debug\GoogleChartsNGraphsControls.pdb
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\bin\Debug\GoogleChartsNGraphsControls.tlb
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\bin\Debug\Newtonsoft.Json.dll
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\bin\Debug\Visualization.dll
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\bin\Debug\Visualization.pdb
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\obj\Debug\GoogleChartsNGraphsControls.csprojResolveAssemblyReference.cache
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\obj\Debug\GoogleChartsNGraphsControls.Resource1.resources
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\obj\Debug\GoogleChartsNGraphsControls.csproj.GenerateResource.Cache
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\obj\Debug\GoogleChartsNGraphsControls.dll
C:\Users\kingj5\Documents\GitHub\googlevisualizationsdotnet\GoogleChartsNGraphsControls\obj\Debug\GoogleChartsNGraphsControls.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions TestGoogleCharsNGraphsControls/Default.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,45 @@
this.GVPieChart2.ChartData(dt);
</pre>

<p />
<h3>Gantt Example</h3>
<cc1:GVGanttChart ID="GVGanttChart1" runat="server" Width="600" Height="400" GviTitle="A Simple Example" />


<pre class="sloppyCode">
Sample Code:

DataTable dt = new DataTable("Gantt");

// specical datatype for the 2nd and 3rd Date columns required for this chart
DataColumn startDate = new DataColumn("Start Date", typeof(DateTime));
startDate.ExtendedProperties.Add("GoogleDateType", Bortosky.Google.Visualization.GoogleDateType.Date);
DataColumn endDate = new DataColumn("End Date", typeof(DateTime));
endDate.ExtendedProperties.Add("GoogleDateType", Bortosky.Google.Visualization.GoogleDateType.Date);

dt.Columns.AddRange(new DataColumn[] {
new DataColumn("Task ID"),
new DataColumn("Task Name"),
startDate,
endDate,
new DataColumn("Duration", typeof(double)) { AllowDBNull = true },
new DataColumn("Percent Complete",typeof(int)) { AllowDBNull = true },
new DataColumn("Dependencies") { AllowDBNull = true }
});

dt.Rows.Add(new object[] {"Research", "Find Sources", new DateTime(2015, 1,1), new DateTime(2015, 1, 5), null, 100, null });
dt.Rows.Add(new object[] { "Write", "Write Paper", null, new DateTime(2015, 1, 9), 3 * 24 * 60 * 60 * 1000, 25, "Research,Outline" });
dt.Rows.Add(new object[] { "Cite", "Create bibliography", null, new DateTime(2015, 1, 7), 1 * 24 * 60 * 60 * 1000, 20, "Research" });
dt.Rows.Add(new object[] { "Complete", "Hand in Paper", null, new DateTime(2015, 1, 10), 1 * 24 * 60 * 60 * 1000, 0, "Cite,Write" });
dt.Rows.Add(new object[] { "Outline", "Outline Paper", null, new DateTime(2015, 1, 6), 1 * 24 * 60 * 60 * 1000, 100, "Research" });



this.GVGanttChart1.DataSource = dt;
this.GVGanttChart1.DataBind();
</pre>


<p />


Expand Down
Loading

0 comments on commit e6f18ea

Please sign in to comment.