Chart title reverts to default

153
3
Jump to solution
a week ago
Kevin_Andras
New Contributor III

I have C# code (pasted below) that creates a chart from a standalone table.  This chart appears in the table of contents, with my specified chart title, as intended:

Kevin_Andras_0-1714163593155.png

 

Then, when I open the chart to view it, the chart title reverts to a default value as if I'd created a chart from a table and did not specify a title.

Kevin_Andras_1-1714163593155.png

I can open Chart Properties and it indicates the correct title:

Kevin_Andras_2-1714163593156.png

Then, as soon as I click in the 'Chart title' text area, the chart updates with the correct title.

I would think that the chart title should appear as intended without having to perform these extra steps.  Is this a bug?  Is there another step my code has to perform?

Is it possible to open the chart programmatically? I don't see any obvious methods.

Thanks!!!

 

 

        public async static void MakeChart(Table table, string field1, string field2, CIMRGBColor lineColor = null, string tableTitle = "")
        {

            try
            {
                string tableName = table.GetName();
                var stTable = MapView.Active.Map.GetStandaloneTablesAsFlattenedList().Where((l) => l.Name == tableName).FirstOrDefault() as StandaloneTable;

                CIMStandaloneTable cimTableDefinition = null;

                await QueuedTask.Run(() =>
                {
                    tableName = table.GetName();

                    cimTableDefinition = stTable.GetDefinition() as CIMStandaloneTable;

                });

                if (lineColor == null) { lineColor = (CIMRGBColor)CIMColor.CreateRGBColor(237, 28, 36); };

                if (tableTitle == "")
                {
                    tableTitle = $"Profile chart for {field1} ";
                }
                    var lineChart = new CIMChart
                {
                    Name = "lineChart",
                    GeneralProperties = new CIMChartGeneralProperties
                    {                        
                        Title = tableTitle,
                    },
                    Series = new CIMChartSeries[]
                        {
                        new CIMChartLineSeries {
                            UniqueName = "lineChartSeries",
                            Name = field1,
                            //Fields = new string[] { "distance" , field1},
                            Fields = new string[] { field2 , field1},
                            ColorType = ChartColorType.SingleColor, //.CustomColor,
                            LineSymbolProperties = new CIMChartLineSymbolProperties {
                            Style = ChartLineDashStyle.Solid,
                            //Color = lineColor2, // new CIMRGBColor { R = 250, G = 150, B = 20 },  //changing this does not have any effect - plots blue line regardless
                            Width = 1,

                            },
                            MarkerSymbolProperties = new CIMChartMarkerSymbolProperties
                            {
                            Color = lineColor
                            }

                        },
                    }
                };
                lineChart.GeneralProperties.Title = tableTitle;
                lineChart.GeneralProperties.ShowTitle = true;  //this is the default setting
                var newChartsLine = new CIMChart[] { lineChart };

                // Add CIM chart to layer defintion
                cimTableDefinition.Charts = newChartsLine.ToArray();
                stTable.SetDefinition(cimTableDefinition);


            }
            catch (Exception ex)
            {
                ErrorLog(ex.ToString());
                GC.Collect();
                return;
            }


        }

0 Kudos
1 Solution

Accepted Solutions
ChristopherAllen
Esri Contributor

Hi @Kevin_Andras ,

Thanks for the question. When you configure the `CIMChartGeneralProperties`, please try adding a line to set the `UseAutomaticTitle`  property to `false` (see documentation here) :

 

 

GeneralProperties = new CIMChartGeneralProperties
{
    Title = tableTitle,
    UseAutomaticTitle = false
}

 

 

This should prevent the title from being reset when the chart is opened in Pro, but please let me know if this does not solve the problem.

Take care,

Chris

View solution in original post

3 Replies
ChristopherAllen
Esri Contributor

Hi @Kevin_Andras ,

Thanks for the question. When you configure the `CIMChartGeneralProperties`, please try adding a line to set the `UseAutomaticTitle`  property to `false` (see documentation here) :

 

 

GeneralProperties = new CIMChartGeneralProperties
{
    Title = tableTitle,
    UseAutomaticTitle = false
}

 

 

This should prevent the title from being reset when the chart is opened in Pro, but please let me know if this does not solve the problem.

Take care,

Chris

Kevin_Andras
New Contributor III

That works! Thank you so much!

ChristopherAllen
Esri Contributor

Thank you for following up and thank you for bringing this to our attention! The code samples online will be updated to include a line that sets this property.

0 Kudos