Skip to main content
RSS feed Subscribe to feed


Skip Navigation LinksHome  Extending the Spotfire Platform  Common Tasks and Idioms  Spotfire Axis Formatting  Line Chart with Individual Scaling

©Spotfire 2011

Line Chart with Individual Scaling

This example creates a line chart with individual scaling. The left scale is formatted as a number with two decimals and the right scale is formatted as a number with no decimals.

Requires Spotfire 2.2.

// Line chart setup is assumed.

 // Set the x-axis.
 lineChart.XAxis.Expression = "Month";

 // Set the y-axis.
 lineChart.YAxis.Expression = "Sum(Sales),Sum(Cost)";

 // Set one line for each measure on the y-axis.
 lineChart.ColorAxis.Expression = "<[Axis.Default.Names]>";

 // Scale each line independently.
 lineChart.YAxis.IndividualScaling = true;
 lineChart.YAxis.IndividualScalingMode = IndividualScalingMode.Color;

 // Set the scale for sales on the right and cost on the left hand side.
 lineChart.YAxis.Scale.IndexedDock["Sum(Cost)"] = ScaleDock.Near;
 lineChart.YAxis.Scale.IndexedDock["Sum(Sales)"] = ScaleDock.Far;

 // Create a formatter for each scale.
 NumberFormatter leftFormatter = (NumberFormatter)DataType.Real.CreateFormatter();
 NumberFormatter rightFormatter = (NumberFormatter)DataType.Real.CreateFormatter();

 // Set the formatter categories to Number.
 leftFormatter.Category = NumberFormatCategory.Number;
 rightFormatter.Category = NumberFormatCategory.Number;

 // Set the number of decimals to 2 on the left and 0 on the right.
 leftFormatter.DecimalDigits = 2;
 rightFormatter.DecimalDigits = 0;

 // Set formatting on the y-axis.
 lineChart.YAxis.Scale.Formatting.IndexedRealFormatter["Sum(Cost)"] = leftFormatter;
 lineChart.YAxis.Scale.Formatting.IndexedRealFormatter["Sum(Sales)"] = rightFormatter;