Jump to content

I'm having trouble with variable charting


Recommended Posts

Hi

I'm having trouble creating a variable chart. I seem to be unable to comprehend how to create one. (my knowledge is severely lacking)

The chart is a stacked column with data from the same year but different "types" (i.e. (InventoryPro, 1 year, 2 year) changing colors in the column.

there are 8 years of data with up to three "types" of data. I haven't been able to make the data change years.

 

There are 5 potential charts based on all data in a record. CornSoyWheat, CornSoy, Corn, Soy, Wheat. The onrecordstart didn't work for me. I tried a ridiculously long statement which I don't know how to simplify or get it to work.

 

The min and max amount for each varies considerably and I don't know if it possible to create a chart like the client example. The client example starts in increments of 1,000 and at 10,000 increments by 10,000 and at 100,000 increments by 250,000.

 

Any help, tip or clues would be appreciated.

 

My attempts are attached.

BH_Chart_FP.zip

Enroll_Forms_CHART_Example.pdf

175561_File_layout_info.pdf

175561_File_layout.pdf

Link to comment
Share on other sites

Hi

I'm having trouble creating a variable chart. I seem to be unable to comprehend how to create one. (my knowledge is severely lacking)

The chart is a stacked column with data from the same year but different "types" (i.e. (InventoryPro, 1 year, 2 year) changing colors in the column.

there are 8 years of data with up to three "types" of data. I haven't been able to make the data change years.

Take a look at the TagsRefGuide.pdf (FusionPro > Documentation > Tags Reference). There's some pretty good information in there about how to make these charts work. Page 36 has an example that seems to almost be exactly what you're trying to do. It's a little bit confusing but I'll try to explain:

the rule that is making the chart is returning a row with cells that represent the columns. The first row should be the header row. The second should be the "1 Year" values for each header, the third should be "2 Year" values for each header, etc. And I think you'll need to make sure that each row has the same number of cells. Like this:

chart = '<rowtype=header><cell>2009<row><cell>2010<row><cell>2011<row><cell>2012<row><cell>2013<row><cell>2014<row><cell>2015<row><cell>2016';
chart += '<row><cell>Year 1'; 
chart += '<cell>' + Field("2009 Corn 1 Year Sign Up");
chart += '<cell>' + Field("2010 Corn 1 Year Sign Up");
chart += '<cell>' + Field("2011 Corn 1 Year Sign Up");
... etc ...
chart += '<cell>' + Field("2015 Corn 1 Year Sign Up");
chart += '<cell>'

Notice that since you don't have a "2016 Corn 1 Year Sign Up" field, I added a blank cell to the end in order to keep the row even with the header row.

There are 5 potential charts based on all data in a record. CornSoyWheat, CornSoy, Corn, Soy, Wheat. The onrecordstart didn't work for me. I tried a ridiculously long statement which I don't know how to simplify or get it to work.

 

The way I would do this is to create a function that you pass the "type" (Corn, Soy, etc) to minimize code and put it in the "Globals" section. That way it can be referenced from all of your rules:

// Chart Function
function Chart(type){
   var data = [["1 Year"],["2 Year"],["InventoryPro"]];
   var years = [2009,2010,2011,2012,2013,2014,2015,2016];
   years.forEach(
       function(s){
           for (var i=0; i<data.length; i++){
               data[i].push(GetValue(s + " " + type + " " + data[i][0]));
           }
   });

   var result = '<row type="header">';
   result += '<cell><cell>' + years.join('<cell>');

   data.map(function(s){return s.join('<cell>');}).forEach(function(s){
       result += '<row><cell>' + s;
   });

   return result;
}

// Helper Function
function GetValue(field){
   try {
       var field = new RegExp('^' + field,'i');
       for(var i in FusionPro.Fields) {
       if(field.test(i))
           return FusionPro.Fields[i];
       }
       return ''
   }
   catch(e) {
       return '';
   }
}

The 'years' array is used to create the header along the x-axis of the chart. The 'data' will hold the values of each row that corresponds to the name in position 0 of the array. The forEach method cycles through the values for the years and looks for fields matching the following format to push into their respective arrays: "Year Type Array-Title." For example "2009 Corn 1 Year" and since it's a regexp, it doesn't care about anything else that comes after the initial match.

 

To call the function, just modify your chart rules to look like this:

return Chart("Corn");

Link to comment
Share on other sites

Stephen,

thanks for your help. It has taken me a bit to get through the first part of the assistance even with it spelled out. I had read the chart portion in the users guide and didn't realize the guide was also telling me to refer to the tags reference guide-thanks-that helped a lot for understanding.

It appears the charts are building properly. I did try remove guides or legends and ended up with a lines on x and y axis.

Is there a way to turn that off? The legend and titles will be pre-printed.

 

The second part of your assistance is succinct but beyond my grasp. I did put the code in globals and modified rules but I'm not sure anything changed.

Is there a shorter-longer way to write a rule that if there are data in corn-soy-wheat to use the cornsoywheat body and if there's data in corn-soy but not wheat use the cornsoy body? again thanks

Leo

Cargill_FP.zip

Link to comment
Share on other sites

Stephen,

thanks for your help. It has taken me a bit to get through the first part of the assistance even with it spelled out. I had read the chart portion in the users guide and didn't realize the guide was also telling me to refer to the tags reference guide-thanks-that helped a lot for understanding.

Good, I'm glad.

It appears the charts are building properly. I did try remove guides or legends and ended up with a lines on x and y axis.

Is there a way to turn that off? The legend and titles will be pre-printed.

To be completely honest, I've never used FusionPro's chart functionality and don't know much about the way it works other than what I've shared in my previous post. That being said, I definitely see what you're talking about with the X and Y axes but have no idea how to turn those lines off. I would probably butt a textbox with a white fill up against the axes you want to disappear (creative – I know).

 

Speaking of which, why are you wanting to hide the Y and X axes? I understand from looking at your example that the Y-axis has a funny way of incrementing (and by "funny" I mean "misleading") but if you're planning to pre-print a Y-axis that goes from 0 - 1,000,000 bushels, your chart is going to be incorrect. FP's chart is ending at the highest value (8,000 bushels for example) and a pre-printed or static Y-axis will give the appearance that the column has a value of 1,000,000. You could set a max value of the Y-axis to be 1,000,000 but that will skew the chart significantly. Anyway, just some food-for-thought.

 

The second part of your assistance is succinct but beyond my grasp. I did put the code in globals and modified rules but I'm not sure anything changed.

What do you mean nothing changed? I thought you just said that the chart was building properly.

 

Is there a shorter-longer way to write a rule that if there are data in corn-soy-wheat to use the cornsoywheat body and if there's data in corn-soy but not wheat use the cornsoy body?

Well, I'm not sure what a "short-long" way to do something is. If you're wanting to trigger pages based on whether or not a record has 1, 2, or 3 charts you can do that. Make these modifications to the "Chart" function that will return nothing if a record doesn't have a value for a specific chart type:

// Chart Function
function Chart(type){
   var data = [["1 Year"],["2 Year"],["InventoryPro"]];
   var years = [2009,2010,2011,2012,2013,2014,2015,2016];
   [color="red"]var empty = true; // Empty flag[/color]
   years.forEach(
       function(s){
           for (var i=0; i<data.length; i++){
              [color="red"] var cell = GetValue(s + " " + type + " " + data[i][0]);
               // If cell is not empty, set empty flag to false
               empty = (empty) ? !cell : empty;
               data[i].push(cell);[/color]
           }
   });

   [color="Red"]// If chart is empty, return nothing
   if (empty)
       return '';[/color]

   var result = '<row type="header">';
   result += '<cell><cell>' + years.join('<cell>');

   data.map(function(s){return s.join('<cell>');}).forEach(function(s){
       result += '<row><cell>' + s;
   });

   return result;
}

Then you can set all of your body pages to "unused" and create an OnRecordStart callback rule:

var charts = {
   Corn: Chart("Corn"),
   Soy: Chart("Soybeans"),
   Wheat: Chart("Wheat")
}

var page = '';
for (var i in charts){
   page += (charts[i]) ? i : '';
}

FusionPro.Composition.SetBodyPageUsage(page, true);

Here's what that's doing: I created an object called "charts" with the properties "Corn," Soy," and "Wheat" each with the value of the chart it should return for that record. Iterate through each property and if the value is not blank (meaning it returns a chart), add it to the 'page' string. So if "Corn" returns a chart, 'page' becomes "Corn" if "Soy" returns a chart, 'page' becomes "CornSoy." And you're left with the page that matches the charts to be displayed. If a record doesn't have a chart, no page will be output.

Link to comment
Share on other sites

It appears the charts are building properly. I did try remove guides or legends and ended up with a lines on x and y axis.

Is there a way to turn that off? The legend and titles will be pre-printed.

Is there a way to turn off what exactly? You can turn off the legend by selecting "None" on the Legend tab of the Chart Properties dialog. You can turn off the titles by just not specifying any on the Titles tab. You can turn off the gridlines by unchecking all of the boxes on the Gridlines tab. And you can turn off the axis labels by unchecking both the "Category (X) axis" and "Value (Y) axis" boxes on the Axis Labels tab (though, if you turn off the Value labels, it may not be obvious what numbers the chart represents).

Link to comment
Share on other sites

HI Ste,

Again thanks for the response. I was trying to trigger my body page and couldn't figure it out. I did go through the data and created a field for a template. It took awhile. I am going to work on the page selection from your example.

 

I think your right about the chart and I believe I will need to use the x y in FusionPro. There are some pretty big ranges. I'm not sure how committed the client is to the large numbers they have in there static piece.

This is one panel in a 12 panel project VDP piece - been trying to figure out this chart piece for a bit. Your help has been tremendous.

thanks again

Leo

Link to comment
Share on other sites

Hi Dan,

I had "turned off" x y - grids and titles. original thought was to place the FusionPro chart onto a predefined grid on the PDF. On the test output there arelines on the x-y axis. example attached.

 

I don't believe its an issue though because I will be using the x y info. The range of values are too much to fit on a predefined grid. The client example chart goes up to 1,000,000 bushels and it looks like the average is around 40,000 to 50,000 bushels.

 

Thanks

Leo

175561_Test_Output 1.pdf

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...