Jump to content

How to make a connection between Mapchart feature layer and line chart?


PBR
Go to solution Solved by PBR,

Recommended Posts

Hello,

I have a MapChart with a feature layer that contains multiple shapes. I also have a line chart that represents a parameter related to all those shapes over time.
I want to write an IronPython script that whenever a shape/shapes is selected the corresponding curve on the line chart is marked and the rest are disappeared.
In my code below, it correctly gets the selected shapes on MapChart and returns the names. For example if I select shapes 1 and 2, it returns List[str](['Tag1', 'Tag2']) on print. 

It should be noted that the Tag1, Tag2,... are the column names of the data table for the line chart.

Any help would be appreciated.

from Spotfire.Dxp.Application.Visuals import *
from System.Collections.Generic import List
from Spotfire.Dxp.Data import *

# Get the current active page
page = Document.ActivePageReference


shapesTable = Document.Data.Tables["Shapefile"]

# Create a cursor for the 'Tag' column in the shapesTable
cursor = DataValueCursor.CreateFormatted(shapesTable.Columns["Tag"])

# Retrieve the marking selection
markings = Document.ActiveMarkingSelectionReference.GetSelection(shapesTable)

# Create a List object to store the retrieved data marking selection
markedTag = List[str]();

#Iterate through the data table rows to retrieve the marked rows
for row in shapesTable.GetRows(markings.AsIndexSet(),cursor):
    value = cursor.CurrentValue
    if value <> str.Empty:
        markedTag.Add(value)

print(markedTag)

lineChartTable = Document.Data.Tables["Table_Wide"]

 

Edited by PBR
Link to comment
Share on other sites

  • PBR changed the title to How to make a connection between Mapchart feature layer and line chart?

hi PBR,

let me restate the problem to confirm i understand:

  • you have a Map Chart with a Marker Layer showing data from Data Table "A"
  • you have a Line Chart showing data from Data Table "B"
  • when one or more markers from the Marker Layer are selected, the Line Chart should update so that only data related to those markers is visible

if i understand correctly, it sounds like you could accomplish this using the Limit data using markings configuration:

  1. Data Tables "A" and "B" must be related first with a common key. it looks like that key is in the [Tag] column. you can configure this relationship in the Data Table Properties dialog.
  2. in your Marker Layer's Properties dialog, choose a Marking to use as your "selection":
    image.png.622bb0b5d4f47ce6affbf04fddb452b3.png
  3. in your Line Chart's Properties dialog, choose a different Marking to use as your selection, and set the Limit data using markings option to use the marking from the previous step:
    image.png.f8fdc312d8f727090ed8993abd5ca6f5.png
  4. still in the Line Chart Properties, change the setting for If no items are marked in the master visualizations, show to All data:
    image.png.d6eb933413f19b23bf2b97aa6e91906a.png

as a result, the Line Chart will display all the data available to it until one or more markers are selected on the Map Chart, at which point the Line Chart will update to show only the data related to those markers.

  • Like 1
Link to comment
Share on other sites

Posted (edited)
14 hours ago, Niko Maresco said:

hi PBR,

let me restate the problem to confirm i understand:

  • you have a Map Chart with a Marker Layer showing data from Data Table "A"
  • you have a Line Chart showing data from Data Table "B"
  • when one or more markers from the Marker Layer are selected, the Line Chart should update so that only data related to those markers is visible

if i understand correctly, it sounds like you could accomplish this using the Limit data using markings configuration:

  1. Data Tables "A" and "B" must be related first with a common key. it looks like that key is in the [Tag] column. you can configure this relationship in the Data Table Properties dialog.
  2. in your Marker Layer's Properties dialog, choose a Marking to use as your "selection":
    image.png.622bb0b5d4f47ce6affbf04fddb452b3.png
  3. in your Line Chart's Properties dialog, choose a different Marking to use as your selection, and set the Limit data using markings option to use the marking from the previous step:
    image.png.f8fdc312d8f727090ed8993abd5ca6f5.png
  4. still in the Line Chart Properties, change the setting for If no items are marked in the master visualizations, show to All data:
    image.png.d6eb933413f19b23bf2b97aa6e91906a.png

as a result, the Line Chart will display all the data available to it until one or more markers are selected on the Map Chart, at which point the Line Chart will update to show only the data related to those markers.

Hi Niko;

Thank you for the reply. Yes, you are right about the problem. I used this method to create the connection, but it has some issues, that is why I thought to use IronPython.
The issue is that my data table B is very large and in wide format (columns: Time, Tag1, Tag2, ...). My data table A related to the shapes has Tag1, Tag2, ... under the Tag column, and Spotfire cannot recognize the relationship between the two tables. So, I changed the format of Table B to long format, and I have Tag1, Tag2, ... in a single Tag column now. However, the load time is very high if I load it in memory, and it slows the performance of the dashboard.
If I load it as an external source, I cannot use averaging on the line chart.
I thought maybe to use the wide format (that is loadded on demand) but use the Ironpython to read the corresponding data from Table B and be able to use averaging on line chart.

Edited by PBR
Link to comment
Share on other sites

  • Solution

I fixed my issue using the below Ironpython script.

from Spotfire.Dxp.Application.Visuals import *
from System.Collections.Generic import List
from Spotfire.Dxp.Data import *

shapesTable = Document.Data.Tables["Shapefile"]

# Create a cursor for the 'Tag' column in the shapesTable
cursor = DataValueCursor.CreateFormatted(shapesTable.Columns["Tag"])

# Retrieve the marking selection
markings = Document.ActiveMarkingSelectionReference.GetSelection(shapesTable)

# Create a List object to store the retrieved data marking selection
markedTags = List[str]();

#Iterate through the data table rows to retrieve the marked rows
for row in shapesTable.GetRows(markings.AsIndexSet(),cursor):
    value = cursor.CurrentValue
    if value <> str.Empty:
        markedTags.Add(value)

if len(markedTags) == 0:
    markedTag = ["Tag 1", "Tag 2", "Tag 3", "Tag 4"]

#Clearing the line chart and plotting the selected Tags 
# vis is a scripting parameter
vis = vis.As[LineChart]()

# Clear the Y-axis expression (removes all plotted lines)
vis.YAxis.Expression = ""

# Build the Y-axis expression (here it is the average)
y_axis_expression = ", ".join(["avg([" + col + "])" for col in markedTags])

# Apply the new Y-axis expression to the line chart
vis.YAxis.Expression = y_axis_expression
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...