Subscribe Bookmark RSS Feed

Annotate Pie Chart (from Graph Builder) with JSL

jb

Community Trekker

Joined:

Sep 23, 2015

I have written JSL to create a Pie Chart (from Graph Builder):

Pie.png

I would like to annotate this Pie Chart (under its legend) with text that says "Responses: 14", for example:

Pie_Annotated.png

 

Is there a way to do this with JSL?  My current script is attached as a file.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

I have reworked the script, showing how the picture form of the pie chart can be incorporated into the final display

/* Scorecard with Annotated Pie */

ClearLog();
NamesDefaultToHere(1);

dt1 = NewTable( "Table1", AddRows(5),
	NewColumn( "Channel", Character, Nominal,
		SetValues({"Call","Email","Facebook","Twitter","Visit"}) ),
	NewColumn( "Pct of Customers", Continuous, Format("Percent"),
		SetValues({.1, .05, .4, .35, .08}) )
);
dt2 = NewTable( "Table2", AddRows(5),
	NewColumn( "Team Member", Character, Nominal,
		SetValues({"Sales Asst A","Sales Asst B","Sales Asst C","Sales Asst D","Sales Asst E"}) ),
	NewColumn( "Rating", Character, Nominal,
		SetValues({"Excellent","Very Good","Excellent","Excellent","Excellent"}) )
);
dt = New Table( "Responses",
	AddRows( 4 ),
	New Column( "Status", Character( 7 ), "Nominal", Set Values( {"Late", "N/A", "On Time", "Pending"} ) ),
	New Column( "Count", Numeric, "Continuous", Format( "Fixed Dec", 12, 0 ), Set Values( [2, 0, 11, 1] ) )
);
gb = dt << GraphBuilder(invisible,
        Size( 150, 180 ),
        ShowControlPanel( 0 ),
        Variables( X( :Status ), Y( :Name( "Count" ) ) ),
        Elements( Pie( X, Y, Legend( 2 ), Label( "Label by Value" ) ) ),
        SendToReport(
          Dispatch({}, "400", ScaleBox, {LegendModel( 2,
              Properties( 0, {FillColor({247, 150, 70})} ),
              Properties( 1, {FillColor({200, 200, 200})} ),
              Properties( 2, {FillColor({155, 187, 89})} ),
              Properties( 3, {FillColor({192, 80, 77})} )
            )}
          ),
          Dispatch({}, "", GraphBuilderContainerBox, AddTextAnnotation(
            Text("Responses 14"), TextBox({157, 102, 232, 135}), BackgroundColor("White")
          )),
          Dispatch( {}, "Graph Builder", OutlineBox, {SetTitle("Survey Responses")} ),
          Dispatch( {}, "graph title", TextEditBox, {SetText("")} ),
          Dispatch( {}, "X title", TextEditBox, {SetText("John Doe (pending)")} ),
          Dispatch( {}, "Y title", TextEditBox, {SetText("")} ),
          Dispatch( {}, "400", LegendBox, {SetTitle("")} )
        )
      );
thepicture = report(gb) << GetPicture;

win = NewWindow( "Customer Service Scorecard",
  TextBox( "Customer Service Scorecard", <<setFontSize(16), <<SetFontStyle("Bold"), <<setWrap(800),
    <<SetWidth(600), <<JustifyText("center")
  ),
  TextBox( "September 2017", <<setFontSize(14), <<SetFontStyle("Bold"), <<setWrap(800),
    <<SetWidth(600), <<JustifyText("center")
  ),
  TextBox( " " ), 
  VListBox(
    HListBox(
      OutlineBox( "Customer Satisfaction",
        TextBox( " " ),
        TextBox( "97%", <<setFontSize(40), <<SetFontStyle("Bold"), <<SetWidth(300), <<JustifyText("center") ),
        TextBox( "of customers are satisfied", <<setFontSize(9), <<SetWidth(300), <<JustifyText("center") )
      ),
      dt1 << GraphBuilder(
        Size(300,200), ShowControlPanel(0), ShowLegend(0),
        Variables( X(:Channel), Y(:Pct of Customers) ),
        Elements( Bar( X,Y,Legend(6) ) ),
        SendToReport(
          Dispatch({}, "Graph Builder", OutlineBox, {Set Title("Preferred Channels")}),
          Dispatch({}, "Channel", ScaleBox, {Labe Row(LabelOrientation("Angled"))}),
          Dispatch({}, "graph title", TextEditBox, {SetText("")}),
          Dispatch({}, "400", LegendBox, {SetTitle("")})
        )
      )
    ),
    HListBox(
      
      thepicture,
      
      
      OutlineBox( "Winning Interactions",
        TextBox( " ", <<SetWidth(300) ),
        DataTableBox( dt2 )  
      )
    )
  )
);



//jrn = CurrentJournal();

/* How do I combine the picture with the rest of the scorecard? */

//jrn << Append( thepicture );
//jrn = win << Journal;
Jim
3 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

All that has to be done to accomplish this, is to add the annotation to the chart, and then to get the script with the annotation.  Once you have that, some minor changes and you have your script.  The major change was that the annotation would not transfer to the journal, but by copying the output into a picture structure, and then posting that picture to the journal, one has the end results you want.

Clear Log();
Names Default To Here( 1 );

dt = New Table( "Responses",
	AddRows( 4 ),
	New Column( "Status", Character( 7 ), "Nominal", Set Values( {"Late", "N/A", "On Time", "Pending"} ) ),
	New Column( "Count", Numeric, "Continuous", Format( "Fixed Dec", 12, 0 ), Set Values( [2, 0, 11, 1] ) )
);

total = 14;
thetext = "Responses\!n" || char(total);
win = New Window( "Scorecard",
	gb = dt << GraphBuilder(
		Size( 150, 180 ),
		ShowControlPanel( 0 ),
		Variables( X( :Status ), Y( :Name( "Count" ) ) ),
		Elements( Pie( X, Y, Legend( 2 ), Label( "Label by Value" ) ) ),
		SendToReport(
			Dispatch(
				{},
				"400",
				ScaleBox,
				{Legend Model(
					2,
					Properties( 0, {Fill Color( {247, 150, 70} )} ),  /* Late:     orange */
					Properties( 1, {Fill Color( {200, 200, 200} )} ),  /* N/A:      grey   */
					Properties( 2, {Fill Color( {155, 187, 89} )} ),  /* On Time:  green  */
					Properties( 3, {Fill Color( {192, 80, 77} )} )   /* Pending:  red    */
				)}
			),
			Dispatch(
			{},
			"",
			GraphBuilderContainerBox,
			Add Text Annotation(
				Text( theText ),
				Text Box( {159, 94, 232, 133} ),
				Background Color( "White" )
			)
		),
			Dispatch( {}, "Graph Builder", OutlineBox, {SetTitle( "Survey Responses (Q3 2017)" )} ),
			Dispatch( {}, "graph title", TextEditBox, {SetText( "" )} ),
			Dispatch( {}, "X title", TextEditBox, {SetText( "John Doe (pending)" )} ),
			Dispatch( {}, "Y title", TextEditBox, {SetText( "" )} ),
			Dispatch( {}, "400", LegendBox, {SetTitle( "" )} )
		)
	)
);
thepicture=report(gb)<<get picture;
jrn = Current Journal();
jrn<<append(thepicture);
Close All( Reports, NoSave );
Close( dt, NoSave );
Jim
jb

Community Trekker

Joined:

Sep 23, 2015

Thanks, Jim.

 

OK, I see that the TextBox is not actually part of GraphBuilder, but rather a picture placed on top of it.  I was able to run your script successfully to create a journal containing one picture.

 

What if the picture was part of a 2x2 scorecard?

 

For example:

  1. OutlineBox with Text
  2. Bar Chart
  3. Picture (Pie Chart with Annotation)
  4. OutlineBox with Table

 

In the attached script, how would I combine the picture with the rest of the scorecard?

 

txnelson

Super User

Joined:

Jun 22, 2012

Solution

I have reworked the script, showing how the picture form of the pie chart can be incorporated into the final display

/* Scorecard with Annotated Pie */

ClearLog();
NamesDefaultToHere(1);

dt1 = NewTable( "Table1", AddRows(5),
	NewColumn( "Channel", Character, Nominal,
		SetValues({"Call","Email","Facebook","Twitter","Visit"}) ),
	NewColumn( "Pct of Customers", Continuous, Format("Percent"),
		SetValues({.1, .05, .4, .35, .08}) )
);
dt2 = NewTable( "Table2", AddRows(5),
	NewColumn( "Team Member", Character, Nominal,
		SetValues({"Sales Asst A","Sales Asst B","Sales Asst C","Sales Asst D","Sales Asst E"}) ),
	NewColumn( "Rating", Character, Nominal,
		SetValues({"Excellent","Very Good","Excellent","Excellent","Excellent"}) )
);
dt = New Table( "Responses",
	AddRows( 4 ),
	New Column( "Status", Character( 7 ), "Nominal", Set Values( {"Late", "N/A", "On Time", "Pending"} ) ),
	New Column( "Count", Numeric, "Continuous", Format( "Fixed Dec", 12, 0 ), Set Values( [2, 0, 11, 1] ) )
);
gb = dt << GraphBuilder(invisible,
        Size( 150, 180 ),
        ShowControlPanel( 0 ),
        Variables( X( :Status ), Y( :Name( "Count" ) ) ),
        Elements( Pie( X, Y, Legend( 2 ), Label( "Label by Value" ) ) ),
        SendToReport(
          Dispatch({}, "400", ScaleBox, {LegendModel( 2,
              Properties( 0, {FillColor({247, 150, 70})} ),
              Properties( 1, {FillColor({200, 200, 200})} ),
              Properties( 2, {FillColor({155, 187, 89})} ),
              Properties( 3, {FillColor({192, 80, 77})} )
            )}
          ),
          Dispatch({}, "", GraphBuilderContainerBox, AddTextAnnotation(
            Text("Responses 14"), TextBox({157, 102, 232, 135}), BackgroundColor("White")
          )),
          Dispatch( {}, "Graph Builder", OutlineBox, {SetTitle("Survey Responses")} ),
          Dispatch( {}, "graph title", TextEditBox, {SetText("")} ),
          Dispatch( {}, "X title", TextEditBox, {SetText("John Doe (pending)")} ),
          Dispatch( {}, "Y title", TextEditBox, {SetText("")} ),
          Dispatch( {}, "400", LegendBox, {SetTitle("")} )
        )
      );
thepicture = report(gb) << GetPicture;

win = NewWindow( "Customer Service Scorecard",
  TextBox( "Customer Service Scorecard", <<setFontSize(16), <<SetFontStyle("Bold"), <<setWrap(800),
    <<SetWidth(600), <<JustifyText("center")
  ),
  TextBox( "September 2017", <<setFontSize(14), <<SetFontStyle("Bold"), <<setWrap(800),
    <<SetWidth(600), <<JustifyText("center")
  ),
  TextBox( " " ), 
  VListBox(
    HListBox(
      OutlineBox( "Customer Satisfaction",
        TextBox( " " ),
        TextBox( "97%", <<setFontSize(40), <<SetFontStyle("Bold"), <<SetWidth(300), <<JustifyText("center") ),
        TextBox( "of customers are satisfied", <<setFontSize(9), <<SetWidth(300), <<JustifyText("center") )
      ),
      dt1 << GraphBuilder(
        Size(300,200), ShowControlPanel(0), ShowLegend(0),
        Variables( X(:Channel), Y(:Pct of Customers) ),
        Elements( Bar( X,Y,Legend(6) ) ),
        SendToReport(
          Dispatch({}, "Graph Builder", OutlineBox, {Set Title("Preferred Channels")}),
          Dispatch({}, "Channel", ScaleBox, {Labe Row(LabelOrientation("Angled"))}),
          Dispatch({}, "graph title", TextEditBox, {SetText("")}),
          Dispatch({}, "400", LegendBox, {SetTitle("")})
        )
      )
    ),
    HListBox(
      
      thepicture,
      
      
      OutlineBox( "Winning Interactions",
        TextBox( " ", <<SetWidth(300) ),
        DataTableBox( dt2 )  
      )
    )
  )
);



//jrn = CurrentJournal();

/* How do I combine the picture with the rest of the scorecard? */

//jrn << Append( thepicture );
//jrn = win << Journal;
Jim