Erledigt!

IronPython-Codebeispiele zum Ändern von Diagrammfarben in Spotfire

Technologie
Programmierung
Datenvisualisierung
Python
Datenanalyse

Fortschritt

6 Schritte abgeschlossen!16,65 Sek.

Antwort

IronPython ist eine beliebte Skriptsprache zum Ändern und Anpassen von TIBCO Spotfire. Im Folgenden finden Sie einige Beispiele dafür, wie Sie Diagrammfarben in Spotfire mit IronPython ändern können:

Beispiel 1: Ändern der Farbe eines Balkendiagramms basierend auf Säulenwerten

from Spotfire.Dxp.Application.Visuals import BarChart from Spotfire.Dxp.Application.Visuals import ColorRule from Spotfire.Dxp.Application.Visuals.VisualContent import BackgroundRule # Get the Bar Chart visualization barChart = vis.As[BarChart]() # Define a color rule colorRule = ColorRule("YourColumnName", "Categorical") colorRule.AddCategoryExpression("\"YourFirstCategory\"", Color.Yellow) colorRule.AddCategoryExpression("\"YourSecondCategory\"", Color.Green) colorRule.AddCategoryExpression("\"YourThirdCategory\"", Color.Blue) # Apply the color rule to the data barChart.ColorRules.Add(colorRule)

Beispiel 2: Festlegen einer bestimmten Farbe für alle Balken

from Spotfire.Dxp.Application.Visuals import BarChart, ColorRule from System.Drawing import Color # Get the Bar Chart visualization barChart = vis.As[BarChart]() # Define a global color rule for all bars globalColorRule = ColorRule(Color.FromArgb(255, 0, 128, 128)) # Teal color # Apply the global color rule barChart.ColorRules.Add(globalColorRule)

Beispiel 3: Ändern der Farben von Liniendiagrammen

from Spotfire.Dxp.Application.Visuals import LineChart, ColorRule from System.Drawing import Color # Get the Line Chart visualization lineChart = vis.As[LineChart]() # Define a color rule lineColorRule = ColorRule("YourColumnName", "Categorical") lineColorRule.AddCategoryExpression("\"YourFirstCategory\"", Color.Red) lineColorRule.AddCategoryExpression("\"YourSecondCategory\"", Color.Green) lineColorRule.AddCategoryExpression("\"YourThirdCategory\"", Color.Blue) # Apply the color rule to the data lineChart.ColorRules.Add(lineColorRule)

Beispiel 4: Bedingte Formatierung für die Hintergrundfarbe

from Spotfire.Dxp.Application.Visuals import BarChart, BackgroundRule from System.Drawing import Color # Get the Bar Chart visualization barChart = vis.As[BarChart]() # Define a background color rule based on a condition backgroundRule = BackgroundRule("YourColumnName") backgroundRule.AddCategoryExpressio backgroundRule.AddBackgroundExpression("[YourColumnName] > 10", Color.FromArgb(255, 255, 0, 0)) # Red for values > 10 backgroundRule.AddBackgroundExpression("[YourColumnName] <= 10", Color.FromArgb(255, 0, 255, 0)) # Green for values <= 10 # Apply the background rule barChart.BackgroundRules.Add(backgroundRule)

Wichtige Hinweise:

  • Ersetzen Sie "YourColumnName" durch den tatsächlichen Spaltennamen in Ihrem Datensatz.
  • Ersetzen Sie "YourFirstCategory", "YourSecondCategory" und "YourThirdCategory" durch die tatsächlichen Kategorienamen, die in Ihrem Datensatz verfügbar sind.
  • Stellen Sie sicher, dass Sie die Farben nach Ihren Wünschen anpassen, indem Sie die ARGB-Werte ändern.

Diese Beispiele sollen Ihnen den Einstieg in das Ändern von Diagrammfarben in Spotfire mit IronPython erleichtern.