POST
|
I made a Python toolbox with a simple tool for testing arcpy's charting functionality in Pro. I'm trying to plot a line chart from these data, which I imported into a geodatabase as a table: x,y 1,4 2,2 3,4 I have a map named "Map" with the above table as the first table in the map. Here's the tool class's execute method: def execute(self, parameters, messages):
aprx = arcpy.mp.ArcGISProject("current")
map = aprx.listMaps("Map")[0]
table = map.listTables()[0]
c = arcpy.Chart('MyChart')
c.type = 'line'
c.xAxis.field = 'x'
c.yAxis.field = 'y'
c.addToLayer(table)
return When I run the tool, a chart is added as shown below the table in the Table of Contents, but when I open the chart, instead of a chart I see "Select Variable(s) in the Chart Properties pane to begin". But the chart properties pane does show the variables selected. If I uncheck and then re-check "y" in the numeric fields list and click Apply, nothing happens. If I right-click the table to manually create a new chart, the chart previously created by my GP tool disappears.
... View more
05-11-2020
11:56 AM
|
1
|
0
|
643
|
POST
|
Hi Uma, It sounds like I'll have to take that into consideration regarding tool activation, and I'll just notify users of the crash fix in 2.6. Thanks for the info! Tim
... View more
04-23-2020
04:10 PM
|
0
|
0
|
790
|
POST
|
If an add-in tool is active, it looks like when you open a chart, OnToolActivateAsync fires again, causing my code to be executed again. Furthermore, when I close the chart, ArcGIS Pro crashes. https://utexas.box.com/s/qx1kidxsnufrgsobw1f83wd3aravjiho Is there any way to prevent the multifiring of OnToolActivateAsync? And not crashing would be nice. I'm in ArcGIS Pro 2.5.0. To test this: 1. Make an add-in with a Pro MapTool. No need for any additional code. Build (I built under Debug/Any CPU). 2. In Visual Studio, click Start. Place a breakpoint in OnToolActivateAsync on the line: return base.OnToolActivateAsync(active); // breakpoint here 3. Start a Pro project with a map. Add a table and make a chart. I tried line and bar charts from two numbers fields and the result was the same, so I suspect chart type doesn't matter. If the chart pane is open, then close it. 4. On the Add-In tab, click the tool to activate it. You should the breakpoint. Press F5 to let code execution continue. 5. Open the chart. When I do this, I hit the breakpoint again. It seems like I shouldn't hit the breakpoint unless I had clicked to activate my tool again. 6. Click the x to close the chart. When I do this, Pro crashes. Attached are sample data, map file, and add-in code for a quick test. I think the crashing is a bug, and I sent the above description in the crash report. I'm posting the question here primarily to answer the question about how to prevent OnToolActivateAsync from firing when a chart is opened. Thanks!
... View more
04-22-2020
06:09 PM
|
0
|
2
|
842
|
POST
|
Hi Uma, For a simple test, I've got a simple standalone table, and my button is just generating a new chart for the table with each click. The table must be named test_data. My add-in has a button with complete code below. using System;
using System.Collections.Generic;
using System.Linq;
using ArcGIS.Core.CIM;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
namespace WRAP_Display
{
internal class TestButton : Button
{
private async void CreateLineChartExample(StandaloneTable table)
{
var def = await QueuedTask.Run(() => { return table.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 };
var title = "Chart " + DateTime.Now.Ticks.ToString();
chart.Name = title;
chart.GeneralProperties = new CIMChartGeneralProperties { Title = title };
var lineSeries = new CIMChartLineSeries
{
Fields = new string[] { "x", "y" },
Name = "Line Chart Series1"
};
chart.Series = new CIMChartSeries[] { lineSeries };
List<CIMChart> updated_charts = new List<CIMChart>();
var charts = def.Charts;
if (charts != null)
updated_charts.AddRange(charts);
updated_charts.Add(chart);
def.Charts = updated_charts.ToArray();
await QueuedTask.Run(() => { table.SetDefinition(def); });
}
protected override void OnClick()
{
StandaloneTable table = MapView.Active.Map.FindStandaloneTables("test_data").FirstOrDefault();
CreateLineChartExample(table);
}
}
} I placed sample data (a .gdb and a .mapx) here: sample_data.zip - Box The sample data is just a file geodatabase table with x and y fields, repeated below in CSV format in case you don't want to or can't get the zip. If you import it, name it test_data. x,y 1,4 2,2 3,4 I'm on current Windows 10, ArcGIS Pro 2.5.0, default Python environment, and no other add-ins except for this one that I am developing. Nothing else in the add-in is listening to events or otherwise messing with the GUI unless invoked via button click. Below is a link to a video illustrating the problem. I click the test button, and even though it creates a chart, no charts appear under the test_data table. When I right-click the table to make a new chart, suddenly the first chart appears. When I click the test button two more times, two additional charts are not visible. When I right-click the table to make a new chart again, the two additional charts are now visible. 2020-04-22_11-42-24 I would like the chart to be visible under the table when the button finishes adding the chart to the table definition. Also, my next question will be how to show the chart pane after the chart is added, though I haven't fully researched how to do that yet. I didn't find anything in searching the documentation, so I was going to poke around in debug mode a bit. Thanks! Tim
... View more
04-22-2020
09:47 AM
|
0
|
1
|
1673
|
POST
|
I can add charts to a layer using code (thanks Stephen Rhea for the charting code). Each click of a button in my add-in adds a new chart to the first layer. (I adapted Stephen's code to use a unique name for each chart.) protected override void OnClick()
{
var layer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
CreateLineChartExample(table);
} After the first click, I see the first chart appear under the layer name in the Table of Contents. However, although subsequent button clicks add new charts, only the first chart is visible in the Table of Contents. If I right-click the layer and click to add a new chart, the other charts suddenly become visible. How do I get the Table of Contents to refresh a layer's chart list? This would be similar to the old IMxDocument.UpdateContents method. I've tried MapView.Active.RedrawAsync(true); but it didn't update the TOC.
... View more
04-21-2020
09:37 AM
|
0
|
5
|
1756
|
POST
|
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.
... View more
04-21-2020
09:19 AM
|
0
|
0
|
1900
|
POST
|
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?
... View more
04-20-2020
12:19 PM
|
0
|
1
|
1900
|
IDEA
|
Actually, brushing is not only not required, but is avoided. The user may want to show different time ranges in each plot, and would thus not want previously generated plots to be automatically updated to reflect whatever selection was on the table.
... View more
04-18-2020
09:39 AM
|
0
|
0
|
1922
|
IDEA
|
Actually, brushing is not only not required, but is avoided. The user may want to show different time ranges in each plot, and would thus not want previously generated plots to be automatically updated to reflect whatever selection was on the table.
... View more
04-18-2020
09:39 AM
|
0
|
0
|
981
|
IDEA
|
+1 for charting functionality in Pro via the SDK! I am porting an ArcMap add-in to Pro. In ArcMap, a user could click a feature in the map to create a plot from data in a related time series table (standalone table in the map). If the user clicked another feature, a second line would be added to the same graph if it was still visible. And so on. Another tool would generate a separate graph for each selected feature in a layer. If a unique value renderer is applied to the feature layer, the graphed line shows up as the same color as the feature. No brushing capabilities (e.g., selecting a data point in the graph will also select the related time series row) are required. I shipped a template tee chart (*.tee) in the add-in file to set a lot of default properties for the appearance of the chart, so that I only had to deal with minimal adjustments in the code. Thanks, Stephen, for initiating this Idea!
... View more
04-18-2020
09:35 AM
|
0
|
1
|
1922
|
IDEA
|
+1 for charting functionality in Pro via the SDK! I am porting an ArcMap add-in to Pro. In ArcMap, a user could click a feature in the map to create a plot from data in a related time series table (standalone table in the map). If the user clicked another feature, a second line would be added to the same graph if it was still visible. And so on. Another tool would generate a separate graph for each selected feature in a layer. If a unique value renderer is applied to the feature layer, the graphed line shows up as the same color as the feature. No brushing capabilities (e.g., selecting a data point in the graph will also select the related time series row) are required. I shipped a template tee chart (*.tee) in the add-in file to set a lot of default properties for the appearance of the chart, so that I only had to deal with minimal adjustments in the code. Thanks, Stephen, for initiating this Idea!
... View more
04-18-2020
09:35 AM
|
0
|
1
|
981
|
POST
|
I'm trying to represent netCDF data in NSIDC EASE Grid North using CF conventions such that ArcGIS shows the data in the place on a map. I figured I'd generate such a file with ArcGIS to see how it defines the coordinate system in netCDF. To test, I took point data in NSIDC EASE Grid North, which I believe is EPSG:3408. I interpolated to raster and converted to netCDF. I've attached the result as from_arc_grid.nc, and the text version as from_arc_grid.cdl. When I use Make NetCDF Raster Layer on that netCDF file, it lines up with the points perfectly. However, I notice the grid mapping variable is fairly light: int lambert_azimuthal_equal_area(lambert_azimuthal_equal_area); lambert_azimuthal_equal_area:grid_mapping_name = "lambert_azimuthal_equal_area"; lambert_azimuthal_equal_area:longitude_of_projection_origin = 0.0; lambert_azimuthal_equal_area:latitude_of_projection_origin = 90.0; lambert_azimuthal_equal_area:false_easting = 0.0; lambert_azimuthal_equal_area:false_northing = 0.0; And in my data variable, fake_var, there is an esri_pe_string attribute that has additional coordinate system details. fake_var:esri_pe_string = "PROJCS[\"NSIDC_EASE_Grid_North\",GEOGCS[\"GCS_Sphere_International_1924_Authalic\",DATUM[\"D_Sphere_International_1924_Authalic\",SPHEROID[\"Sphere_International_1924_Authalic\",6371228.0,0.0]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",0.0],PARAMETER[\"Latitude_Of_Origin\",90.0],UNIT[\"Meter\",1.0]]"; What I'd like to do is drop the esri_pe_string attribute, and add attributes to the grid mapping variable to fully define the coordinate system, using just the CF conventions with no Esri magic. I tried this using attributes defined in CF (test.nc and test.cdl), and I also tried using a WKT string which is what the esri_pe_string appears to be (test_wkt.nc and test_wkt.cdl). I got the WKT string straight from the EPSG website for 3408. When I do this and bring the fake_var variable in as a raster layer, the coordinate system is undefined. The grid does line up perfectly with the original data and with from_arc_grid.nc as long as the data frame's coordinate system is EASE Grid North. However, for other projections, my test grids wind up in the wrong place. (I also tried by just copying the esri_pe_string value to the crs_wkt attribute but got the same results as when using the EPSG:3408 string). Got any ideas?
... View more
01-09-2020
09:27 AM
|
0
|
0
|
640
|
POST
|
I put it in the .cs file for the gallery. private bool _isInitialized;
protected override void OnDropDownOpened()
{
Initialize();
}
private void Initialize()
{
if (_isInitialized)
return;
// Code to add your gallery items...
// Items added. Now wrap up.
AlwaysFireOnClick = true; // Required so you can click a gallery item again that you had clicked last time
_isInitialized = true;
}
... View more
06-05-2019
06:55 AM
|
1
|
1
|
1075
|
POST
|
A visualintersect value of true means the symbol used for the feature is taken into account. So for example if you represented a city (point feature class) with a point symbol consisting of a large circle that is 100 pixels across in screen units, then if the search geometry intersects that circle (as if the circle were a polygon feature in the map), then that city feature will be returned even if the search geometry doesn't actually intersect the city's latitude and longitude point coordinates. At least that's what I have determined based on experimentation.
... View more
05-15-2019
01:03 PM
|
0
|
0
|
806
|
Title | Kudos | Posted |
---|---|---|
1 | 05-11-2020 11:56 AM | |
3 | 06-03-2021 09:16 AM | |
2 | 12-13-2020 12:16 PM | |
1 | 12-02-2020 12:11 PM | |
1 | 06-05-2019 06:55 AM |
Online Status |
Offline
|
Date Last Visited |
09-05-2024
06:00 PM
|