Export (0) Print
Expand All

Create a Chart

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

This sample shows how to create a visualization (chart). This sample works with Microsoft Dynamics CRM Online only. It is a full sample that includes the authentication code needed to communicate with the Microsoft Dynamics CRM Online server.

This sample code can be found in the following files in the SDK download:

Server\FullSample\CreateVisualization\CS\
Server\FullSample\CreateVisualization\VB\

Example

The following code shows how to create a data visualization (chart).

[C#]
// Create a saved query to select opportunities for the sales pipeline.
savedquery newSavedQuery = new savedquery();
newSavedQuery.name = "Sales Pipeline Funnel";
newSavedQuery.fetchxml = @"
        <fetch version='1.0' 
            output-format='xml-platform' 
            mapping='logical' 
            distinct='false'>
            <entity name='opportunity'>
<attribute name='name'/>
<attribute name='customerid'/>
<attribute name='estimatedvalue'/>
<attribute name='statuscode'/>
<attribute name='opportunityid'/>
<order attribute='name' descending='false'/>
            </entity>
        </fetch>
        ";
newSavedQuery.returnedtypecode = EntityName.opportunity.ToString();
newSavedQuery.layoutxml = @"<grid name='resultset' object='3' jump='name' 
select='1' icon='1' preview='1'>
<row name='result' id='opportunityid'>
    <cell name='name' width='300' />
    <cell name='customerid' width='150' />
    <cell name='estimatedvalue' width='100' />
    <cell name='statuscode' width='100' />
</row>
            </grid>";
newSavedQuery.querytype = new CrmNumber();

newSavedQuery.querytype.Value = SavedQueryType.MainApplicationView;

Guid viewId = service.Create(newSavedQuery);

// Set The presentation XML string.
string presentationXml = @"
    <Chart Palette='BrightPastel'>
        <Series>
            <Series _Template_='All' ShadowOffset='2' 
BorderColor='64, 64, 64' BorderDashStyle='Solid' 
BorderWidth='1' IsValueShownAsLabel='true' 
Font='Tahoma, 6.75pt, GdiCharSet=0' 
LabelForeColor='100, 100, 100' 
CustomProperties='FunnelLabelStyle=Outside' 
ChartType='Funnel'>
    <SmartLabelStyle Enabled='True' />
    <Points />
            </Series>
        </Series>
        <ChartAreas>
            <ChartArea _Template_='All' BackColor='Transparent' 
BorderColor='Transparent' BorderDashStyle='Solid'>
<Area3DStyle Enable3D='True' IsClustered='True' />
            </ChartArea>
        </ChartAreas>
        <Legends>
            <Legend _Template_='All' Alignment='Center' 
LegendStyle='Table' Docking='Bottom' 
IsEquallySpacedItems='True' BackColor='White' 
BorderColor='228, 228, 228' BorderWidth='0' 
Font='Tahoma, 8pt, GdiCharSet=0' 
ShadowColor='0, 0, 0, 0' ForeColor='100, 100, 100'>
            </Legend>
        </Legends>
        <Titles>
            <Title _Template_='All' 
Font='Tahoma, 9pt, style=Bold, GdiCharSet=0' 
ForeColor='102, 102, 102'>
            </Title>
        </Titles>
        <BorderSkin PageColor='Control' 
            BackColor='CornflowerBlue' 
            BackSecondaryColor='CornflowerBlue' />
    </Chart>";

// Set the data XML string.
string dataXml = @"
    <datadefinition>
        <fetchcollection>
            <fetch mapping='logical' 
count='10' 
aggregate='true'>
<entity name='opportunity'>
    <attribute name='estimatedvalue_base' 
        aggregate='sum' 
        alias='sum_estimatedvalue_base'/>
    <attribute name='stepname' groupby='true' alias='stepname'/>
    <order alias='stepname' descending='false' />
</entity>
            </fetch>
        </fetchcollection>
        <categorycollection>
            <category>
<measurecollection>
    <measure alias='sum_estimatedvalue_base'/>
</measurecollection>
            </category>
        </categorycollection>
    </datadefinition>";

// Create the visualization entity instance.
savedqueryvisualization newSavedQueryVisualization = new savedqueryvisualization();

newSavedQueryVisualization.name = "Example Visualization";
newSavedQueryVisualization.presentationdescription = presentationXml;
newSavedQueryVisualization.datadescription = dataXml;
newSavedQueryVisualization.savedqueryid = new Lookup();
newSavedQueryVisualization.savedqueryid.Value = viewId;

Guid newSavedQueryVisualizationId = service.Create(newSavedQueryVisualization);

//Publish the Opportunity entity customizations.
PublishXmlRequest request = new PublishXmlRequest();

request.ParameterXml = @"
      <importexportxml>
            <entities>
<entity>opportunity</entity>
</entities>
            <nodes/>
            <securityroles/>
            <settings/>
            <workflows/>
        </importexportxml>";

// Execute the request.
PublishXmlResponse response = (PublishXmlResponse)service.Execute(request);

See Also

Concepts


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft