Public classes to create a chart through the API

1052
9
Jump to solution
01-15-2018 02:18 PM
StephenRhea
New Contributor III

I'm able to create line charts, profile graphs, etc. on a feature layer, but I have to use the CIMChart classes in the ArcGIS.Core.Internal.CIM namespace. I don't see any documentation online (yay IntelliSense), and the namespace implies that it isn't intended for "public" use. Are there any plans to move the charting API into a publicly documented namespace? If not, what is the best way to plan on creating charts in the future?

Thanks

0 Kudos
1 Solution

Accepted Solutions
StephenRhea
New Contributor III

Hey Karen, see below. The feature layer being passed in is a point layer that is the result of a line-of-sight analysis. The M-value represents the distance from the observer to that point.

private async void CreateLineChartExample(FeatureLayer featureLayer)
{
	var featureLayerDefinition = await QueuedTask.Run(() => { return featureLayer.GetDefinition(); });

	var chart = new CIMChart();

	var xAxis = new CIMChartAxis { Title = "X-Axis" };
	var yAxis = new CIMChartAxis { Title = "Y-Axis" };

	chart.Axes = new CIMChartAxis[] { xAxis, yAxis };

	chart.MapSelectionHandling = ChartMapSelectionHandling.None;

	chart.Name = "Line Chart";

	chart.GeneralProperties = new CIMChartGeneralProperties
	{
		Footer = "Distance in meters",
		Title = "Line Chart Test",
		BackgroundSymbolProperties = new CIMChartFillSymbolProperties
		{
			Color = ColorFactory.Instance.WhiteRGB
		},
		GridLineSymbolProperties = new CIMChartLineSymbolProperties
		{
			Color = ColorFactory.Instance.BlackRGB,
			Style = ChartLineDashStyle.Dot,
			Width = 1
		}
	};			

	var lineSeries = new CIMChartLineSeries
	{
		Fields = new string[] { "M", "Z" },
		Name = "Line Chart Series1"
	};

	chart.Series = new CIMChartSeries[] { lineSeries };

	featureLayerDefinition.Charts = new CIMChart[] { chart };

	await QueuedTask.Run(() => { featureLayer.SetDefinition(featureLayerDefinition); });
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

9 Replies
DrewFlater
Esri Contributor

Hi Stephen, it isn't currently in the near or mid-term roadmap for Pro to have a charting API in the Pro .Net SDK. This could perhaps be in our long term plan if there is enough user demand. I would encourage you to add your thoughts to an ArcGIS Idea, which will allow others to see and comment and add fuel to the fire

I would like to add that programmatic charting in ArcGIS Pro has already started, but through the Python/ArcPy library. Chart—ArcPy Classes | ArcGIS Desktop We started with ArcPy because the first request we heard was to make charts via geoprocessing script tools built with Python.

Just out of curiosity can you explain your business case for creating charts using the .Net SDK? What kind of charts are you making, what interaction pattern do you want, etc. If we understand your use case it will help us design and understand why this work should be a priority. This would also be great info to add to the ArcGIS Idea if you can create one.

Thanks,

Pro Charts dev team

0 Kudos
StephenRhea
New Contributor III

Thanks, Drew! I'll add it to the list. Thanks for the note on Python; I'll use that for now.

We have a tool in a few ArcMap extensions that allows users to sketch a line segment, then runs LOS analysis on the segment and generates a profile graph so the user has multiple visualizations.

0 Kudos
DrewFlater
Esri Contributor

Thanks for the information and for creating the idea: https://community.esri.com/ideas/14452 

We will keep track of this and prioritize our work as the idea gains support.

0 Kudos
KarenMeinstein
Occasional Contributor

Hey Stephen,  I'm currently trying to create a simple line chart in Pro.  You said you were able to do that using the CIMChart classes.  I've been poking around trying to do that without any luck.  Could you possible provide the code that you used?

0 Kudos
StephenRhea
New Contributor III

Hey Karen, see below. The feature layer being passed in is a point layer that is the result of a line-of-sight analysis. The M-value represents the distance from the observer to that point.

private async void CreateLineChartExample(FeatureLayer featureLayer)
{
	var featureLayerDefinition = await QueuedTask.Run(() => { return featureLayer.GetDefinition(); });

	var chart = new CIMChart();

	var xAxis = new CIMChartAxis { Title = "X-Axis" };
	var yAxis = new CIMChartAxis { Title = "Y-Axis" };

	chart.Axes = new CIMChartAxis[] { xAxis, yAxis };

	chart.MapSelectionHandling = ChartMapSelectionHandling.None;

	chart.Name = "Line Chart";

	chart.GeneralProperties = new CIMChartGeneralProperties
	{
		Footer = "Distance in meters",
		Title = "Line Chart Test",
		BackgroundSymbolProperties = new CIMChartFillSymbolProperties
		{
			Color = ColorFactory.Instance.WhiteRGB
		},
		GridLineSymbolProperties = new CIMChartLineSymbolProperties
		{
			Color = ColorFactory.Instance.BlackRGB,
			Style = ChartLineDashStyle.Dot,
			Width = 1
		}
	};			

	var lineSeries = new CIMChartLineSeries
	{
		Fields = new string[] { "M", "Z" },
		Name = "Line Chart Series1"
	};

	chart.Series = new CIMChartSeries[] { lineSeries };

	featureLayerDefinition.Charts = new CIMChart[] { chart };

	await QueuedTask.Run(() => { featureLayer.SetDefinition(featureLayerDefinition); });
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
KarenMeinstein
Occasional Contributor

Hi Stephen,  

Thanks so much for the help!  I never would have figured this out!  I wish they would document this stuff.  It would make life a lot easier...

0 Kudos
StephenRhea
New Contributor III

You're welcome; happy to help! I'm sure this will eventually make it into documentation.

0 Kudos
TimWhiteaker
Occasional Contributor II

Hi Stephen and Karen,

I tried the code exactly as above, except I swapped in my own fields (both are number fields) on line 34. The code hangs when calling SetDefinition on line 42.

I'm on Pro 2.5.0.  I'm calling CreateLineChartExample within a Button's OnClick event. 

var t = QueuedTask.Run(() => CreateLineChartExample(layer));
t.Wait();


I can also call the function asynchronously, which makes Pro responsive again, but no chart ever appears.  Did you have to do anything else to make this work?

0 Kudos
TimWhiteaker
Occasional Contributor II

According to ProConcepts Framework: "You should never use the Wait method on a GUI thread."

The code below worked for me.

protected override void OnClick()
{
    var layer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
    CreateLineChartExample(layer);
}‍‍‍‍‍

I'm having another problem, where after the first chart is added, if I execute the code again (with a different unique chart name), the table of contents isn't refreshed to show the second (and third, and fourth, and fifth...) chart. But that's a problem for another thread.

0 Kudos