1. You can get the wks names from the graph itself. This may not be the most elegant method but should work...string wks_names()
{
string sWks,sList;
StringArray sa(0);
GraphLayer gl = Project.ActiveLayer();
int nPlots = gl.DataPlots.Count();
if( !nPlots ) return "";
foreach (DataPlot dp in gl.DataPlots)
{
sWks = dp.GetDatasetName(); // dataset name
sWks = sWks.GetToken(0,'_'); // wks name
sa.Add(sWks); // add to string array
}
sList = sa[0]; // now strip duplicates (may not be necessary)
for(int i=1;i<sa.GetSize();i++)
if( sList.Find(sa[i])==-1 )
sList.Format("%s, %s",sList,sa[i]);
return sList;
}
2. The legend is a text label (GraphObject) named 'legend'. The following code (similar to first) creates a new legend string in which the wks name is beside the symbol (represented by \l(i))...void my_legend()
{
string sWks,sLegend;
GraphLayer gl = Project.ActiveLayer();
int nPlots = gl.DataPlots.Count();
if( !nPlots ) return;
int i;
foreach (DataPlot dp in gl.DataPlots)
{
i++;
sWks = dp.GetDatasetName(); // dataset name
sWks = sWks.GetToken(0,'_'); // wks name
if( i==1 )
sLegend = "\l(1) " + sWks; // first line
else
sLegend.Format("%s\n\l(%d) %s",sLegend,i,sWks)
}
gl.LT_execute("legend"); // create legend
GraphObject goLegend = gl.GraphObjects("legend");
if( goLegend.IsValid() )
goLegend.Text = sLegend; // replace the text
}
Mike Buess
Origin WebRing Member
Edited by - Mike Buess on 09/30/2004 2:18:01 PM