BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I apologize if this is in the wrong forum, but I'm looking for some pretty advanced technical information. I am wanting to incorporate the ActiveX object for SAS/GRAPH v9 into a C# Winforms app for interactive on-the-fly data loading and visualization of pre-summarized data (the benefits being that SAS/GRAPH v9 is very robust and already incorporates hardware acceleration, and would save me a lot of time from having to write my own graphing library or buy a commercial one (or download a free one) that isn't nearly as feature-rich when I already have SAS EG), and so far I have been successful in doing so. I managed to find a post out there on SAS-L doing a google search and came across a way to do it for the previous version of SAS/GRAPH (this was for getting it to work in VB6) and went from there.

I have the object created in a C# Winforms app doing a 3D Bar Chart as I'll show in the example below, have set all the data, roles, and properties for the objects for the graph, even have it doing a smooth auto-rotate on the Y axis (which looks really cool).

The only thing that's left to tackle is sorting the data set, which seems to not work right. When the graph appears no matter what you set the SetSortOrder of a Category role to, it will appear as either "Data" for Text or "Ascending" for Numeric. I'm sure I can presort the data as a workaround, but would like to be able to do it programmatically without having to interface the data options. If anyone already knows how to do this (i.e. they've done it in VB/C++/VBA/etc) I'd appreciate the help. I figured this might be a good place to start since you can place a ActiveX control in Excel or Access and someone may have already figured this out. Here are some snippets from my test code, and the part where I'm telling the Date variable to have a SetSortOrder("Descending") is what seems to have no effect:

// Variable and Interface Declarations

AxSASGRPH9Lib.AxSASGraph axSASGraph1;

SASGRPH9Lib.SASGraphChart myChart;
SASGRPH9Lib.SASGraphChartData myChartData;
SASGRPH9Lib.SASGraphData myData;
SASGRPH9Lib.SASGraphDataVariable myVar;
SASGRPH9Lib.SASGraphDataVariableNumeric myNumVar;
SASGRPH9Lib.SASGraphDataVariableText myTextVar;
SASGRPH9Lib.SASGraphLine myLine;
SASGRPH9Lib.SASGraphChartDataRole myRole;
SASGRPH9Lib.SASGraphLegend myLegend;
SASGRPH9Lib.SASGraphBarChart myBarChart;
SASGRPH9Lib.SASGraphPresentationFormat myFormat;
SASGRPH9Lib.SASGraphPresentationFormatValue myFormatValue;
SASGRPH9Lib.SASGraphDataPoint myPoint;
SASGRPH9Lib.SASGraphUnit myUnit;
SASGRPH9Lib.SASGraphTileChart myTitle;
SASGRPH9Lib.SASGraphFill myFill;
SASGRPH9Lib.SASGraphAxis myAxis;
SASGRPH9Lib.SASGraphAppearanceScheme myScheme;

....

myChart = this.axSASGraph1.GetChartAtPosition(0);
myChartData = myChart.GetChartData();

myData = myChartData.GetDataObject();

int z = myData.GetNumberOfVariables();
z--;
for (; z >= 0; z--)
{
string varStr = myData.GetVariableByIndex((short)z).GetName();
myData.RemoveVariableByName(varStr);
}

myNumVar = (SASGRPH9Lib.SASGraphDataVariableNumeric)myData.NewVariable("Numeric", "Date", "Date");
myTextVar = (SASGRPH9Lib.SASGraphDataVariableText)myData.NewVariable("Text", "Scenario_ID", "Scenario_ID");
myNumVar = (SASGRPH9Lib.SASGraphDataVariableNumeric)myData.NewVariable("Numeric", "Total_Dollars", "Total_Dollars");

myVar = (SASGRPH9Lib.SASGraphDataVariable)myData.GetVariable("Date");
myVar.SetFormat("MMDDYY10.0");

myVar = (SASGRPH9Lib.SASGraphDataVariable)myData.GetVariable("Total_Dollars");
myVar.SetFormat("COMMA32.0");

myRole = myChartData.SetRoleVariable("Response", "Total_Dollars");
myRole.SetSortOrder("None");
myRole.SetStatistic("SUM");

myRole = myChartData.SetRoleVariable("Series", "Scenario_ID");
myRole.SetSortOrder("None");
myRole.SetDiscreteCategorization();

myRole = myChartData.SetRoleVariable("Category", "Date");
myRole.SetSortOrder("Descending");
myRole.SetDiscreteCategorization();

myNumVar = (SASGRPH9Lib.SASGraphDataVariableNumeric)myData.GetVariable("Date");
myNumVar.Append(17532);
myTextVar.AppendFrequency(1);
myTextVar = (SASGRPH9Lib.SASGraphDataVariableText)myData.GetVariable("Scenario_ID");
myTextVar.Append("110");
myTextVar.AppendFrequency(1);
myNumVar = (SASGRPH9Lib.SASGraphDataVariableNumeric)myData.GetVariable("Total_Dollars");
myNumVar.Append(5000);
myNumVar.AppendFrequency(1);

.... (Several more lines of appending data in the same manner)

myChartData.SetDataObject(myData);

myChartData.PreBuild();
myChart = this.axSASGraph1.NewChart("Bar");
myChart.SetChartData(myChartData);
myChartData.PostBuild();

myLine = myChart.GetOutline();
myLine.SetVisible(false);
myChart.SetLabelStatistic("SUM");
myChart.SetLabelsVisible(true);
myChart.SetOutline(myLine);
myChart.SetStyleBy("Series");
myBarChart = (SASGRPH9Lib.SASGraphBarChart)myChart;
myBarChart.SetBarShape("Cylinder");
myScheme = this.axSASGraph1.GetAppearanceScheme();
//myScheme.SetStyleName("Astronomy");

myScheme.SetSchemeName("Magellan");

this.axSASGraph1.SetLegendsVisible(true);
this.axSASGraph1.Set2DView(false);

this.axSASGraph1.SetAdvancedOptions("PerspectiveDepth", 0.5);
this.axSASGraph1.SetAdvancedOptions("Projection", 3);

...
1 REPLY 1
deleted_user
Not applicable
Nvm, should have been "myChartData = this.axSASGraph1.NewChartData();" and not "myChartData = myChart.GetChartData();".

... Anyone C#/VB.NET developers want to see the full source code in action? (:

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Discussion stats
  • 1 reply
  • 685 views
  • 0 likes
  • 1 in conversation