Jaa


3D charts. Chart Generator tool II

One of the new features in NAV 2009 is the new chart (KPI) object, described in more details here:

NAV 2009 - How to generate charts / KPIs

 

This post describes how to make 3D rotatable charts, and includes an update to the Chart Generator Tool which makes is simple to make your own 3D charts.

 

For basics about how to make charts, please refer to the post linked above. To add the 3rd dimension to your charts, all you need to do is to add a Z-axis. This gives you charts that can look like this:

 

Item stacks by location:

 ItemStacksbyLocation

 

Customer balance by discount group:

CustBalanceByDiscGroup

 

A chart automatically becomes a 3D chart by adding a Z-axis to the chart definition, for example like this:

- <ZAxis ShowTitle="false">

<Field Name="Customer Disc. Group" />

</ZAxis>

And the presence of a Z-axis will automatically make the user able to rotate the chart.

 

Below, you can find the following:

  1. Chart definition for the two charts pictured above, so you can import them into your own CROUS database
  2. Chart Generator Tool, updated so that it can handle Z-axis, so you can create your own charts.

 

 

Lars Lohndorf-Larsen

Microsoft Dynamics UK

Microsoft Customer Service and Support (CSS) EMEA

 

 

Chart definitions

 

Item stacks by location:

- <ChartDefinition xmlns="urn:schemas-microsoft-com:dynamics:NAV:MetaObjects" xmlns:xsd="**https://www.w3.org/2001/XMLSchema**" xmlns:xsi="**https://www.w3.org/2001/XMLSchema-instance**" Type="Column">

- <Title>

<Text ID="ENU">Items by location</Text>

</Title>

- <Table ID="32">

- <Filters>

- <Filter>

<Field Name="Item No. " />

<Value>70000|70001|70002|70003</Value>

</Filter>

</Filters>

</Table>

- <XAxis ShowTitle="true">

- <Title>

<Text ID="ENU">Location Code</Text>

</Title>

<Field Name="Location Code" />

</XAxis>

- <ZAxis ShowTitle="false">

<Field Name="Item No. " />

</ZAxis>

- <YAxis ShowTitle="false">

- <Measures>

- <Measure Operator="Sum">

<Field Name="Quantity" />

</Measure>

</Measures>

</YAxis>

</ChartDefinition>

 

 

 

Customer balance by discount group:

- <ChartDefinition xmlns="urn:schemas-microsoft-com:dynamics:NAV:MetaObjects" xmlns:xsd="**https://www.w3.org/2001/XMLSchema**" xmlns:xsi="**https://www.w3.org/2001/XMLSchema-instance**" Type="Column">

- <Title>

<Text ID="ENU">Customer Balance</Text>

</Title>

- <Table ID="18">

<Filters />

</Table>

- <XAxis ShowTitle="true">

- <Title>

<Text ID="ENU">No.</Text>

</Title>

<Field Name="No. " />

</XAxis>

- <ZAxis ShowTitle="false">

<Field Name="Customer Disc. Group" />

</ZAxis>

- <YAxis ShowTitle="false">

- <Measures>

- <Measure Operator="Sum">

<Field Name="Balance (LCY) " />

</Measure>

</Measures>

</YAxis>

</ChartDefinition>

 

 

 

Chart Generator Tool II

This is an improvement to the Chart Generator tool from this post. This version adds the possibility to set a Z-axis, and in this way make 3D charts.

 

To use it, save the code below to a text file. Then remove all [RemoveMe] from the text after checking that the object types and IDs won't replace existing objects that you want to keep. Then import it into NAV from Object Designer, and compile.

 

for instructions of how to use the tool, follow the link above to the original post.

 

 

 

OBJECT Table [RemoveMe]72000 Chart Generator
{
  OBJECT-PROPERTIES
  {
    Date=17/10/08;
    Time=12:00:00;
    Version List=CGT;
  }
  PROPERTIES
  {
    OnInsert=BEGIN
               IF Chart.GET(Company,ID) THEN
                 ERROR('Chart already exists in table 2000000078. Run form 9182 and delete it, or use a different ID.');
             END;

    LookupFormID=Form72000;
  }
  FIELDS
  {
    { 1   ;   ;Company             ;Text30         }
    { 2   ;   ;ID                  ;Code20        ;NotBlank=Yes }
    { 10  ;   ;Name                ;Text50        ;OnValidate=BEGIN
                                                                Title := Name;
                                                              END;
                                                               }
    { 11  ;   ;Title               ;Text50         }
    { 15  ;   ;Type                ;Option        ;OptionString=Column,Point }
    { 16  ;   ;Table ID            ;Integer       ;OnValidate=BEGIN
                                                                MODIFY;
                                                              END;
                                                               }
    { 17  ;   ;Table Name          ;Text30        ;FieldClass=FlowField;
                                                   CalcFormula=Lookup(Object.Name WHERE (Type=CONST(Table),
                                                                                         ID=FIELD(Table ID)));
                                                   Editable=No }
    { 20  ;   ;XAxis Field ID      ;Integer        }
    { 21  ;   ;XAxis Field Name    ;Text80        ;OnValidate=BEGIN
                                                                IF "XAxis Field Name" <> '' THEN BEGIN
                                                                  FieldRec.SETRANGE(TableNo,"Table ID");
                                                                  FieldRec.SETRANGE(FieldName,"XAxis Field Name");
                                                                  FieldRec.FINDFIRST;
                                                                  "XAxis Field ID" := FieldRec."No.";
                                                                  "XAxis Field Name" := FieldRec.FieldName;
                                                                  "XAxis Field Caption" := FieldRec."Field Caption";
                                                                  "XAxis title" := FieldRec."Field Caption";
                                                                END ELSE BEGIN
                                                                  "XAxis Field ID" := 0;
                                                                  "XAxis Field Name" := '';
                                                                  "XAxis Field Caption" := '';
                                                                  "XAxis title" := '';
                                                                END;
                                                              END;
                                                               }
    { 22  ;   ;XAxis Field Caption ;Text80         }
    { 23  ;   ;XAxis title         ;Text80         }
    { 24  ;   ;XAxis Show Title    ;Boolean       ;InitValue=Yes }
    { 30  ;   ;YAxis fields        ;Integer       ;FieldClass=FlowField;
                                                   CalcFormula=Count("Chart Generator YAxis" WHERE (Company=FIELD(Company),
                                                                                                    ID=FIELD(ID)));
                                                   Editable=No }
    { 35  ;   ;ZAxis Field Name    ;Text80        ;OnValidate=BEGIN
                                                                IF "ZAxis Field Name" <> '' THEN BEGIN
                                                                  FieldRec.SETRANGE(TableNo,"Table ID");
                                                                  FieldRec.SETRANGE(FieldName,"ZAxis Field Name");
                                                                  FieldRec.FINDFIRST;
                                                                END;
                                                              END;
                                                               }
    { 38  ;   ;ZAxis Show Title    ;Boolean        }
  }
  KEYS
  {
    {    ;Company,ID                              ;Clustered=Yes }
  }
  FIELDGROUPS
  {
  }
  CODE
  {
    VAR
      Chart@1000 : Record 2000000078;
      FieldRec@1102601000 : Record 2000000041;

    BEGIN
    END.
  }
}

OBJECT Table [RemoveMe]72001 Chart Generator Filter
{
  OBJECT-PROPERTIES
  {
    Date=17/10/08;
    Time=12:00:00;
    Version List=CGT;
  }
  PROPERTIES
  {
    OnInsert=BEGIN
               TESTFIELD("Filter Field ID");
             END;

  }
  FIELDS
  {
    { 1   ;   ;Company             ;Text30         }
    { 2   ;   ;ID                  ;Code20         }
    { 3   ;   ;Line No.            ;Integer        }
    { 10  ;   ;Filter Field ID     ;Integer       ;OnValidate=BEGIN
                                                                IF "Filter Field ID" <> 0 THEN BEGIN
                                                                   ChartGen.GET(Company,ID);
                                                                   ChartGen.TESTFIELD("Table ID");
                                                                   FieldRec.GET(ChartGen."Table ID","Filter Field ID");
                                                                   "Filter Field Name" := FieldRec.FieldName;
                                                                END ELSE
                                                                   "Filter Field Name" := '';
                                                              END;
                                                               }
    { 11  ;   ;Filter Field Name   ;Text30         }
    { 15  ;   ;Filter Value        ;Text30         }
  }
  KEYS
  {
    {    ;Company,ID,Line No.                     ;Clustered=Yes }
  }
  FIELDGROUPS
  {
  }
  CODE
  {
    VAR
      ChartGen@1102601001 : Record 72000;
      FieldRec@1102601000 : Record 2000000041;

    BEGIN
    END.
  }
}

OBJECT Table [RemoveMe]72003 Chart Generator YAxis
{
  OBJECT-PROPERTIES
  {
    Date=17/10/08;
    Time=12:00:00;
    Version List=CGT;
  }
  PROPERTIES
  {
    OnInsert=BEGIN
               TESTFIELD("YAxis Measure Field ID");
             END;

    LookupFormID=Form72003;
    DrillDownFormID=Form72003;
  }
  FIELDS
  {
    { 1   ;   ;Company             ;Text30         }
    { 2   ;   ;ID                  ;Code20         }
    { 3   ;   ;Line No.            ;Integer        }
    { 10  ;   ;YAxis Measure Field ID;Integer      }
    { 11  ;   ;YAxis Measure Field Caption;Text30  }
    { 12  ;   ;Mearure Operator    ;Option        ;OptionString=Sum,Count }
    { 20  ;   ;Show Title          ;Boolean        }
  }
  KEYS
  {
    {    ;Company,ID,Line No.                     ;Clustered=Yes }
  }
  FIELDGROUPS
  {
  }
  CODE
  {

    BEGIN
    END.
  }
}

OBJECT Form [RemoveMe]72000 Chart Generator List
{
  OBJECT-PROPERTIES
  {
    Date=17/10/08;
    Time=12:00:00;
    Version List=CGT;
  }
  PROPERTIES
  {
    Width=16500;
    Height=6710;
    TableBoxID=1;
    SourceTable=Table72000;
  }
  CONTROLS
  {
    { 1   ;TableBox     ;220  ;220  ;16060;5500 ;HorzGlue=Both;
                                                 VertGlue=Both }
    { 2   ;TextBox      ;0    ;0    ;4400 ;0    ;HorzGlue=Both;
                                                 Visible=No;
                                                 ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr=Company }
    { 3   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=2;
                                                 InColumnHeading=Yes }
    { 4   ;TextBox      ;0    ;0    ;1700 ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr=ID }
    { 5   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=4;
                                                 InColumnHeading=Yes }
    { 6   ;TextBox      ;0    ;0    ;4400 ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr=Name }
    { 7   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=6;
                                                 InColumnHeading=Yes }
    { 8   ;TextBox      ;0    ;0    ;4400 ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr=Title }
    { 9   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=8;
                                                 InColumnHeading=Yes }
    { 10  ;TextBox      ;0    ;0    ;550  ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr=Type }
    { 11  ;Label        ;0    ;0    ;0    ;0    ;ParentControl=10;
                                                 InColumnHeading=Yes }
    { 12  ;TextBox      ;0    ;0    ;1700 ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr="Table ID" }
    { 13  ;Label        ;0    ;0    ;0    ;0    ;ParentControl=12;
                                                 InColumnHeading=Yes }
    { 14  ;CommandButton;4400 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Default=Yes;
                                                 PushAction=LookupOK;
                                                 InvalidActionAppearance=Hide }
    { 15  ;CommandButton;6820 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Cancel=Yes;
                                                 PushAction=LookupCancel;
                                                 InvalidActionAppearance=Hide }
    { 16  ;CommandButton;14080;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 PushAction=FormHelp }
    { 17  ;MenuButton   ;9240 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 CaptionML=ENU=Chart;
                                                 Menu=MENUITEMS
                                                 {
                                                   { ID=18;
                                                     PushAction=RunObject;
                                                     CaptionML=ENU=Filters;
                                                     RunObject=Form 72001;
                                                     RunFormLink=Company=FIELD(Company),
                                                                 ID=FIELD(ID) }
                                                   { ID=20;
                                                     PushAction=RunObject;
                                                     CaptionML=ENU=XAxis;
                                                     RunObject=Form 72002;
                                                     RunFormLink=Field1=FIELD(Company),
                                                                 Field2=FIELD(ID) }
                                                   { ID=21;
                                                     PushAction=RunObject;
                                                     CaptionML=ENU=YAxis;
                                                     RunObject=Form 72003;
                                                     RunFormLink=Company=FIELD(Company),
                                                                 ID=FIELD(ID) }
                                                 }
                                                  }
    { 19  ;MenuButton   ;11660;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 CaptionML=ENU=F&unctions;
                                                 Menu=MENUITEMS
                                                 {
                                                   { ID=22;
                                                     PushAction=RunObject;
                                                     ShortCutKey=F11;
                                                     CaptionML=ENU=Generate Chart;
                                                     RunObject=Codeunit 72000 }
                                                 }
                                                  }
  }
  CODE
  {
    VAR
      Chart@1000 : Record 2000000078;

    BEGIN
    END.
  }
}

OBJECT Form [RemoveMe]72001 Chart Filters
{
  OBJECT-PROPERTIES
  {
    Date=17/10/08;
    Time=12:00:00;
    Version List=CGT;
  }
  PROPERTIES
  {
    Width=12150;
    Height=6710;
    TableBoxID=1;
    SourceTable=Table72001;
    AutoSplitKey=Yes;
    DelayedInsert=Yes;
  }
  CONTROLS
  {
    { 1   ;TableBox     ;220  ;220  ;11710;5500 ;HorzGlue=Both;
                                                 VertGlue=Both }
    { 2   ;TextBox      ;0    ;0    ;1700 ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr="Filter Field ID";
                                                 OnLookup=BEGIN
                                                            ChartGen.GET(Company,ID);
                                                            ChartGen.TESTFIELD("Table ID");
                                                            FieldRec.SETRANGE(TableNo,ChartGen."Table ID");

                                                            IF FORM.RUNMODAL(FORM::"Field List",FieldRec) = ACTION::LookupOK

THEN
                                                              VALIDATE("Filter Field ID",FieldRec."No.");
                                                          END;
                                                           }
    { 3   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=2;
                                                 InColumnHeading=Yes }
    { 4   ;TextBox      ;0    ;0    ;4400 ;0    ;HorzGlue=Both;
                                                 ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr="Filter Field Name" }
    { 5   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=4;
                                                 InColumnHeading=Yes }
    { 6   ;TextBox      ;0    ;0    ;4400 ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr="Filter Value" }
    { 7   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=6;
                                                 InColumnHeading=Yes }
    { 8   ;CommandButton;4890 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Default=Yes;
                                                 PushAction=LookupOK;
                                                 InvalidActionAppearance=Hide }
    { 9   ;CommandButton;7310 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Cancel=Yes;
                                                 PushAction=LookupCancel;
                                                 InvalidActionAppearance=Hide }
    { 10  ;CommandButton;9730 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 PushAction=FormHelp }
  }
  CODE
  {
    VAR
      ChartGen@1000 : Record 72000;
      FieldRec@1001 : Record 2000000041;

    BEGIN
    END.
  }
}

OBJECT Form [RemoveMe]72003 YAxis List
{
  OBJECT-PROPERTIES
  {
    Date=17/10/08;
    Time=12:00:00;
    Version List=CGT;
  }
  PROPERTIES
  {
    Width=10000;
    Height=6710;
    TableBoxID=1;
    SourceTable=Table72003;
    AutoSplitKey=Yes;
    DelayedInsert=Yes;
  }
  CONTROLS
  {
    { 1   ;TableBox     ;220  ;220  ;9560 ;5500 ;HorzGlue=Both;
                                                 VertGlue=Both }
    { 2   ;TextBox      ;0    ;0    ;1700 ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr="YAxis Measure Field ID";
                                                 OnLookup=BEGIN
                                                            ChartGen.GET(Company,ID);
                                                            ChartGen.TESTFIELD("Table ID");
                                                            FieldRec.SETRANGE(TableNo,ChartGen."Table ID");

                                                            IF FORM.RUNMODAL(FORM::"Field List",FieldRec) = ACTION::LookupOK

THEN BEGIN
                                                              "YAxis Measure Field ID" := FieldRec."No.";
                                                              "YAxis Measure Field Caption" := FieldRec."Field Caption";
                                                            END;
                                                          END;
                                                           }
    { 3   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=2;
                                                 InColumnHeading=Yes }
    { 4   ;TextBox      ;0    ;0    ;4400 ;0    ;HorzGlue=Both;
                                                 ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr="YAxis Measure Field Caption" }
    { 5   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=4;
                                                 InColumnHeading=Yes }
    { 6   ;TextBox      ;0    ;0    ;550  ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 SourceExpr="Mearure Operator" }
    { 7   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=6;
                                                 InColumnHeading=Yes }
    { 8   ;CheckBox     ;0    ;0    ;1700 ;0    ;ParentControl=1;
                                                 InColumn=Yes;
                                                 ShowCaption=No;
                                                 SourceExpr="Show Title" }
    { 9   ;Label        ;0    ;0    ;0    ;0    ;ParentControl=8;
                                                 InColumnHeading=Yes }
    { 10  ;CommandButton;2740 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Default=Yes;
                                                 PushAction=LookupOK;
                                                 InvalidActionAppearance=Hide }
    { 11  ;CommandButton;5160 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Cancel=Yes;
                                                 PushAction=LookupCancel;
                                                 InvalidActionAppearance=Hide }
    { 12  ;CommandButton;7580 ;5940 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 PushAction=FormHelp }
  }
  CODE
  {
    VAR
      ChartGen@1000 : Record 72000;
      FieldRec@1001 : Record 2000000041;

    BEGIN
    END.
  }
}

OBJECT Form [RemoveMe]72004 Chart Generator Card
{
  OBJECT-PROPERTIES
  {
    Date=17/10/08;
    Time=12:00:00;
    Version List=CGT;
  }
  PROPERTIES
  {
    Width=16170;
    Height=6490;
    SourceTable=Table72000;
  }
  CONTROLS
  {
    { 1   ;TabControl   ;220  ;220  ;15730;5280 ;HorzGlue=Both;
                                                 VertGlue=Both;
                                                 PageNamesML=ENU=General }
    { 4   ;TextBox      ;3850 ;990  ;2750 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr=ID }
    { 5   ;Label        ;440  ;990  ;3300 ;440  ;ParentControl=4 }
    { 6   ;TextBox      ;3850 ;1650 ;5500 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 NextControl=12;
                                                 SourceExpr=Name }
    { 7   ;Label        ;440  ;1650 ;3300 ;440  ;ParentControl=6 }
    { 8   ;TextBox      ;3850 ;2200 ;5500 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr=Title }
    { 9   ;Label        ;440  ;2200 ;3300 ;440  ;ParentControl=8 }
    { 10  ;TextBox      ;3850 ;3520 ;2750 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr=Type }
    { 11  ;Label        ;440  ;3520 ;3300 ;440  ;ParentControl=10 }
    { 12  ;TextBox      ;3850 ;2860 ;1700 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr="Table ID";
                                                 OnLookup=BEGIN
                                                            Object.SETRANGE(Type,Object.Type::Table);
                                                            IF FORM.RUNMODAL(FORM::Objects,Object) = ACTION::LookupOK THEN
                                                              "Table ID" := Object.ID;
                                                          END;

                                                 OnAfterValidate=BEGIN
                                                                   CALCFIELDS("Table Name");
                                                                 END;
                                                                  }
    { 13  ;Label        ;440  ;2860 ;3300 ;440  ;ParentControl=12 }
    { 21  ;TextBox      ;12980;990  ;2750 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 NextControl=1102601000;
                                                 SourceExpr="XAxis Field Name";
                                                 OnLookup=BEGIN
                                                            TESTFIELD("Table ID");
                                                            FieldRec.SETRANGE(TableNo,"Table ID");

                                                            IF FORM.RUNMODAL(FORM::"Field List",FieldRec) = ACTION::LookupOK

THEN
                                                              VALIDATE("XAxis Field Name",FieldRec.FieldName);
                                                          END;
                                                           }
    { 22  ;Label        ;9570 ;990  ;3300 ;440  ;ParentControl=21 }
    { 20  ;TextBox      ;12980;1650 ;2750 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr="XAxis Field Caption" }
    { 23  ;Label        ;9570 ;1650 ;3300 ;440  ;ParentControl=20 }
    { 24  ;CheckBox     ;12980;2750 ;440  ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 ShowCaption=No;
                                                 SourceExpr="XAxis Show Title" }
    { 25  ;Label        ;9570 ;2750 ;3300 ;440  ;ParentControl=24 }
    { 27  ;TextBox      ;12980;2200 ;2750 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr="XAxis title" }
    { 28  ;Label        ;9570 ;2200 ;3300 ;440  ;ParentControl=27 }
    { 1102601000;TextBox;12980;3410 ;1700 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr="YAxis fields" }
    { 1102601001;Label  ;9570 ;3410 ;3300 ;440  ;ParentControl=1102601000 }
    { 1102601002;TextBox;5720 ;2860 ;3630 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr="Table Name" }
    { 1102601003;TextBox;12980;4070 ;2750 ;440  ;ParentControl=1;
                                                 InPage=0;
                                                 SourceExpr="ZAxis Field Name";
                                                 OnLookup=BEGIN
                                                            TESTFIELD("Table ID");
                                                            FieldRec.SETRANGE(TableNo,"Table ID");

                                                            IF FORM.RUNMODAL(FORM::"Field List",FieldRec) = ACTION::LookupOK

THEN
                                                              VALIDATE("ZAxis Field Name",FieldRec.FieldName);
                                                          END;
                                                           }
    { 1102601004;Label  ;9570 ;4070 ;3300 ;440  ;ParentControl=1102601003 }
    { 14  ;CommandButton;13750;5720 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 PushAction=FormHelp }
    { 15  ;MenuButton   ;11330;5720 ;2200 ;550  ;HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 CaptionML=ENU=&Chart;
                                                 Menu=MENUITEMS
                                                 {
                                                   { ID=16;
                                                     PushAction=LookupTable;
                                                     ShortCutKey=F5;
                                                     CaptionML=ENU=L&ist }
                                                   { ID=26;
                                                     PushAction=RunObject;
                                                     CaptionML=ENU=Filters;
                                                     RunObject=Form 72001;
                                                     RunFormLink=Company=FIELD(Company),
                                                                 ID=FIELD(ID) }
                                                   { ID=17;
                                                     PushAction=RunObject;
                                                     CaptionML=ENU=YAxis;
                                                     RunObject=Form 72003;
                                                     RunFormLink=Company=FIELD(Company),
                                                                 ID=FIELD(ID) }
                                                   { ID=18;
                                                     MenuItemType=Separator }
                                                   { ID=19;
                                                     PushAction=RunObject;
                                                     ShortCutKey=F11;
                                                     CaptionML=ENU=Generate Chart;
                                                     RunObject=Codeunit 72000 }
                                                 }
                                                  }
  }
  CODE
  {
    VAR
      FieldRec@1001 : Record 2000000041;
      Object@1002 : Record 2000000001;
      XAxisField@1000 : Text[30];

    BEGIN
    END.
  }
}

OBJECT Codeunit [RemoveMe]72000 Chart Generator Mgt
{
  OBJECT-PROPERTIES
  {
    Date=17/10/08;
    Time=12:00:00;
    Version List=CGT;
  }
  PROPERTIES
  {
    TableNo=72000;
    OnRun=BEGIN
            CreateXML(Rec);

            MESSAGE('Chart %1 was created / updated.',Chart.ID);
          END;

  }
  CODE
  {
    VAR
      Chart@1015 : Record 2000000078;
      ChartGen@1003 : Record 72000;
      ChartFilters@1008 : Record 72001;
      ChartYAxis@1012 : Record 72003;
      "3TierMgt"@1013 : Codeunit 419;
      XMLDoc@1000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft

XML, v4.0'.DOMDocument";
      DomNode@1001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-

00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode";
      DomNode2@1006 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-

00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode";
      DomTextNode@1002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF87-7B36-11D2-B20E-

00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMText";
      DomAttribute@1004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF85-7B36-11D2-B20E-

00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMAttribute";
      DomNodeList@1009 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF82-7B36-11D2-B20E-

00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNodeList";
      DomProcessInstruction@1005 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF89-7B36-11D2-B20E-

00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMProcessingInstruction";
      NameSpace@1007 : Text[80];
      i@1010 : Integer;
      TempFileName@1014 : Text[250];
      Debug@1016 : Boolean;
      DebugFileName@1102601000 : Text[250];
      IStream@1102601001 : InStream;

    PROCEDURE CreateXML@1(ChartGenerator@1000 : Record 72000);
    BEGIN
      //=== Enable debug and filename to save the xml document to disk
      Debug := FALSE;
      DebugFileName := '';
      //===

      CREATE(XMLDoc);
      XMLDoc.async(FALSE);

      // Initialize document and set namespaces
      NameSpace := 'urn:schemas-microsoft-com:dynamics:NAV:MetaObjects';

      DomNode := XMLDoc.createNode(1,'ChartDefinition',NameSpace);
      DomAttribute := XMLDoc.createAttribute('xmlns:xsd');
      DomAttribute.value := 'https://www.w3.org/2001/XMLSchema';
      DomNode.attributes.setNamedItem(DomAttribute);
      DomAttribute := XMLDoc.createAttribute('xmlns:xsi');
      DomAttribute.value := 'https://www.w3.org/2001/XMLSchema-instance';
      DomNode.attributes.setNamedItem(DomAttribute);

      // add chart type
      DomAttribute := XMLDoc.createAttribute('Type');
      CASE ChartGenerator.Type OF
        ChartGenerator.Type::Column:
          DomAttribute.value := 'Column';
        ChartGenerator.Type::Point:
          DomAttribute.value := 'Point';
      END;
      DomNode.attributes.setNamedItem(DomAttribute);
      XMLDoc.appendChild(DomNode);

      AddNode('ChartDefinition','Title','');
      AddNode('ChartDefinition/Title','Text',ChartGenerator.Title);
      AddAttribute('ChartDefinition/Title/Text','ID','ENU');
      AddNode('ChartDefinition','Table','');
      AddAttribute('ChartDefinition/Table','ID',FORMAT(ChartGenerator."Table ID"));
      AddNode('ChartDefinition/Table','Filters','');

      // Filters
      ChartFilters.SETRANGE(Company,ChartGenerator.Company);
      ChartFilters.SETRANGE(ID,ChartGenerator.ID);
      IF ChartFilters.FINDSET THEN
        REPEAT
          AddNode('ChartDefinition/Table/Filters','Filter','');
          AddNode('ChartDefinition/Table/Filters/Filter','Field','');
          AddAttribute('ChartDefinition/Table/Filters/Filter/Field','Name',ChartFilters."Filter Field Name");
          AddNode('ChartDefinition/Table/Filters/Filter','Value',ChartFilters."Filter Value");
        UNTIL ChartFilters.NEXT = 0;

      // XAxis
      ChartGenerator.TESTFIELD("XAxis Field Name");

      AddNode('ChartDefinition','XAxis','');
      AddAttribute('ChartDefinition/XAxis','ShowTitle',BooleanFormat(ChartGenerator."XAxis Show Title")); ///
      AddNode('ChartDefinition/XAxis','Title','');
      AddNode('ChartDefinition/XAxis/Title','Text',ChartGenerator."XAxis title");
      AddAttribute('ChartDefinition/XAxis/Title/Text','ID','ENU');
      AddNode('ChartDefinition/XAxis','Field','');
      AddAttribute('ChartDefinition/XAxis/Field','Name',ChartGenerator."XAxis Field Name");

      // ZAxis///
      IF ChartGenerator."ZAxis Field Name" <> '' THEN BEGIN
        AddNode('ChartDefinition','ZAxis','');
        AddAttribute('ChartDefinition/ZAxis','ShowTitle',BooleanFormat(ChartGenerator."ZAxis Show Title"));
        AddNode('ChartDefinition/ZAxis','Field','');
        AddAttribute('ChartDefinition/ZAxis/Field','Name',ChartGenerator."ZAxis Field Name");
      END;

      // YAxis
      ChartYAxis.SETRANGE(Company,ChartGenerator.Company);
      ChartYAxis.SETRANGE(ID,ChartGenerator.ID);
      IF ChartYAxis.FINDSET THEN BEGIN
        AddNode('ChartDefinition','YAxis','');
        AddAttribute('ChartDefinition/YAxis','ShowTitle',BooleanFormat(ChartYAxis."Show Title"));
        AddNode('ChartDefinition/YAxis','Measures','');

        REPEAT
          AddNode('ChartDefinition/YAxis/Measures','Measure','');
          AddAttribute('ChartDefinition/YAxis/Measures/Measure','Operator',FORMAT(ChartYAxis."Mearure Operator"));
          AddNode('ChartDefinition/YAxis/Measures/Measure','Field','');
          AddAttribute('ChartDefinition/YAxis/Measures/Measure/Field','Name',FORMAT(ChartYAxis."YAxis Measure Field

Caption"));
        UNTIL ChartYAxis.NEXT = 0;
      END;

      TempFileName := TEMPORARYPATH + '\' + FORMAT(CREATEGUID) + '.xml';

      XMLDoc.save(TempFileName);

      IF NOT Chart.GET(ChartGenerator.Company,ChartGenerator.ID) THEN BEGIN
        Chart.Company := ChartGenerator.Company;
        Chart.ID := ChartGenerator.ID;
        Chart.Name := ChartGenerator.Name;
        Chart.INSERT;
      END;
      Chart.BLOB.IMPORT(TempFileName);
      Chart.MODIFY;

      IF Debug THEN
        XMLDoc.save(DebugFileName);

      // Clean up
      IF EXISTS(TempFileName) THEN
        ERASE(TempFileName);
      CLEAR(DomNode);
      CLEAR(XMLDoc);
    END;

    PROCEDURE AddNode@2(AddToNode@1000 : Text[120];NodeName@1001 : Text[120];NodeValue@1002 : Text[120]);
    BEGIN
      DomNodeList := XMLDoc.selectNodes(AddToNode);
      DomNode := DomNodeList.item(DomNodeList.length - 1);

      DomNode2 := XMLDoc.createNode(1,NodeName,NameSpace);
      DomTextNode := XMLDoc.createTextNode(NodeValue);
      DomNode2.appendChild(DomTextNode);
      DomNode.appendChild(DomNode2);
    END;

    PROCEDURE AddAttribute@3(AddToNode@1000 : Text[120];AttributeName@1001 : Text[120];AttributeValue@1002 : Text[120]);
    BEGIN
      DomNodeList := XMLDoc.selectNodes(AddToNode);
      DomNode := DomNodeList.item(DomNodeList.length - 1);

      DomAttribute := XMLDoc.createAttribute(AttributeName);
      DomAttribute.value := AttributeValue;
      DomNode.attributes.setNamedItem(DomAttribute);
    END;

    PROCEDURE BooleanFormat@4(Boo@1000 : Boolean) : Text[30];
    BEGIN
      IF Boo THEN
        EXIT('true');

      EXIT('false');
    END;

    EVENT XMLDoc@1000::ondataavailable@198();
    BEGIN
    END;

    EVENT XMLDoc@1000::onreadystatechange@-609();
    BEGIN
    END;

    BEGIN
    END.
  }
}

Comments

  • Anonymous
    October 19, 2008
    PingBack from http://blogs.msdn.com/nav_developer/archive/2008/08/20/nav-2009-how-to-generate-charts-kpis.aspx

  • Anonymous
    March 18, 2011
    When I attempt to make a 3D Chart, I get an error that Form 72002 does not exist. I will have a programmer look at it. Thanks for the great Chart Creation Tool. The native Dynamics NAV Chart Export/Import functionality is very weak. Have you considered transforming to pages and using in RTC? Your solutions are appreciated.