Download Chart Code Behind and Give Specific Name

  1. #1

    Download Chart Code Behind and Give Specific Name

    Hello, I am creating a chart using Ext.Net; now, I've observed in the examples how the saving into an image and download is perfromed from the client side by using the following syntax:

    <script>
        var saveChart = function (btn) {
            Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function (choice) {
                if (choice === 'yes') {
                    btn.up('window').down('chart').download();
                }
            });
        };
    </script>
    This works perfectly fine, but I was wondering if it is possible to Download the Chart as an image from SERVER Side and naming it with a desired value.

    Thanks in advance!
  2. #2
    Hello @faridhajnal!

    The image is rendered on client-side, so the server knows nothing about it at all. There are ways to render it server-side, but it would be using 3rd party libraries like PhantomJS.

    Another way would be making the user, after having the chart rendered, upload the image to the server. I'm not really sure this makes sense in your scenario but, at first, if the image can be generated locally, there's not much point in generating it locally, uploading it to the server, and then downloading.

    As for the file name, you can determine it with the options parameter of the download method. For example:
    btn.up('window').down('chart').download({ filename: "MyChart.jpg" });
    Sencha's chart documentation on download() method.

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thank you very much for your reply, unfortunately I wasn't clear with my description.
    What I need is a way to access the 'download chart' function from my .cs file [Code Behind]; this is, to name my Image file according to results on my database, is this possible ?

    Thanks.
  4. #4
    The function is purely JavaScript, so you can't just access it from code behind.

    You can though, set the filename variable using a code behind call, so when the download occurs, it uses the file name defined by your code behind.

    You can do something like:
    X.AddScript("fileName = 'FilenameChosen.png';");
    And have the fileName variable be global in the JavaScript scope. (declaring var fileName inside a <script/> tag on your aspx code).
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Thank you ! I am a bit novice when it comes to combining JS and C#, this helped a lot and solve the problem! I'll check the documentation on that types of functions to get better! Thanks again
  6. #6
    I'm really glad it helped! I hope you enjoy Ext.NET!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. How to give border color for Stack chart or barchart
    By praveencat123 in forum 2.x Help
    Replies: 0
    Last Post: Dec 23, 2015, 8:09 AM
  2. [CLOSED] How to show solid horizontal line at specific Y value in entire chart?
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Apr 22, 2014, 9:24 AM
  3. [CLOSED] How to hide tooltip of specific data point in line chart?
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 18, 2014, 11:35 AM
  4. [CLOSED] Is there any way we can give custom legend label in chart
    By advBackOffice in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 05, 2012, 4:15 PM
  5. Replies: 2
    Last Post: Oct 24, 2012, 2:27 PM

Tags for this Thread

Posting Permissions