5 Replies Latest reply on Nov 17, 2006 5:34 AM by Mark.P.

    Print charts

    Mark.P. Level 1
      I'm building a dashboard and would like to add a Print button. I'm just in the testing/researching phase and have found a pretty simple solution to it. The one thing I don't like is it prints the background color, is there a way to print only the pie chart and not the "Adobe Grey" that surrounds or bounds it?

      Thanks
        • 1. Re: Print charts
          upshotvideo Level 1
          You should look into creating a component for your printJob. Then you can layout it out however you want. I make a component with all the elements I want to print all in a Vbox with white BG. I put a chart in there along with labels,etc that contain nothing but IDs. Then in my component that displays the chart, etc, i have a functon thats creates the printJob,(when print button is pressed) then makes an instance of my component that holds the elements to be printed. Then I set the dataprovider for the chart in the print component to the same as the one that is displayed on the screen. Then addChild(youPrintComponent),add it to your printJob.addObject(), then removedChild(youPrintComponent). This is a good way to get the print out to look exactly how you want it, and different from your apps interface.
          • 2. Re: Print charts
            Mark.P. Level 1
            Thank you, but in my "Print Tests" I have the pie chart in a VBox with the background set to white. And just for tests I set the background of the application to white as well and I still get the grey bacground. Could there be a print property I need to set as well?

            Also -

            I'm working thru the printing options/code slowely so for now I'm just running off the basic sample in the documentation. I see that by using addObject it adds that oject on a seperate page. What is the best way to add an object to the same page? If there's a sample or tutorial out there you can direct me to that would be great.

            Thanks
            • 3. Re: Print charts
              Mark.P. Level 1
              I was printing the pie so in my code I was adding the id to the pie chart, "myPie", when I should have been using the id to the VBox, "myVBox".

              The second part to my earlier reply still stands if anyone knows.

              Thanks!
              • 4. Re: Print charts
                upshotvideo Level 1
                The only way to achieve this that I know of is to do what I said in my first response. It may sound confusing, but its really not. I'm not sure of a tutorial out there, but i know that in the book, Flex Training From the Source, there is a really good chapter on printing.
                Ill try and break it down for you. Start with something simple:
                Make a new component (use VBox and give it a white BG)... add a few labels and give them ids. Then in your app mxml file, import that component(class) at the top of your AS.
                Somewhere in your mxml, make a print button that fires a print function. In that function make your printJob object like you are doing now. start it. PrintJob.start().
                Then make an instance of the component you made with the labels.
                var pc:YourPrintComp = new YourPrintComp();
                Then add child to your app.
                addChild(pc);
                now type pc. (then you see the label ids you made. Now give them text values).
                pc.label1.text="hello printer";
                pc.label2.text ="hello again";
                Now add that object to your printJob.
                YourPrintJob.addObject(pc);
                YourPrintJob.send();
                removeChild(pc) -- so the user never actually sees your print component on the screen.
                Thats it. start off simple so it all sinks in. Then you can add charts, etc, and just like you added text values to the labels, you would add dataproviders to your charts. You then see how you can format what gets printed in any way you want.
                • 5. Re: Print charts
                  Mark.P. Level 1
                  Yep, I see what you're saying; you're basically creating a pre-layed out page that will be printed with the data passed. I went out and got the book last night so I'll be going over it this weekend. Thanks for your time, it really helped me get thru this much quicker than if I was to do it on my own.

                  Now that I see Flex can print with many options and it comes out nice and crisp here’s what I plan on doing. My app is going to allow the user to select the charts and grids they want to print (alaCart style) so now all I have to do is figure out how to let them select what they need/want and print it on the number of pages needed for the space needed. They way I have it now is with addObject which creates a new page for each object they select, so if they selected 5 or 6 things, that’s the number of pages they’re printing. That doesn’t make for a smart report. And the other way is to create a pre-layed out, hidden page and just pass the data to it, but that will print everything I have on the space. So I’m getting close.

                  Thanks Again!