[CLOSED] Chart Export Data

  1. #1

    [CLOSED] Chart Export Data

    I am looking to export data held in a Charts store, but it is late and I will try in the morning. A quick look around I found the GridPanel -> System.Data -> DataTable. Would this be a good place to start?
    Last edited by Daniil; Nov 13, 2012 at 10:14 AM. Reason: [CLOSED]
  2. #2
    Hi Chris,

    Yes, this example is good.

    Also there are two "specialized" examples.
    https://examples2.ext.net/#/search/export
  3. #3
    Both of the Ext.Net examples that depict exporting data have there controls created in Markup.



    I am creating my controls in behind code and ran into an error "The control with ID 'ChartStore' not found" when try to export the data. The charts look fantastic and everything works. I am just trying to add some additional features to the chart now.

    Behind Code segment ...
    ...
    Chart byMonthChart = new Chart();
    byMonthChart.ID = "CrtsChart";
    byMonthChart.ClientIDMode = ClientIDMode.Static;
    ...
    ...
    Store store = new Store();
    store.ID = "ChartStore";
    store.ClientIDMode = ClientIDMode.Static;
    store.SubmitData += new Store.AjaxSubmitDataEventHandler(ChartStore_Submit);
    
    Model model = new Model();
    ...
    store.Model.Add(model);
    store.DataSource = theData;
    store.DataBind();
    
    byMonthChart.Store.Add(store);
    .....
    Markup ...
    ...
    <HtmlBin>
       <script type="text/javascript">
          var exportData = function (format)
             App.ExportFormatType.setValue(format);
             var store = App.CrtsChart.store;
    
             store.submitData(null, { isUpload: true});
          }
       </script>
    </HtmlBin>
    
       <ext:Hidden ID="ExportFormatType" runat="server" ClientIDMode="Static" />
       ...
    <DockedItems>
    ...
       <ext:Button  runat="server" Tooltip="Export" Icon="PageExcel" >
          <Listener>
             <Click handler="exportData('xls');" />
          </Listener>
       </ext:Button>
       ...
    </DockedItems>
    ...
    This is also part of my Behind Code ...
    protected void Page_Load(object sender, EventArgs e)
       {
       if (!X.IsAjaxRequest)
          {
          ...
          BuildChart();
          ...
          }
       }
    Is there something that I am obviously missing, or do I need to work up a scaled down example?
  4. #4
    Well, you don't recreate a Store during its SubmitData event, therefore it is not found.

    A client side listener with a DirectMethod call looks to be a solution for you.

    Please use a GridPanel's getRowsValues method to get its data to send to a server as a parameter of a DirectMethod.
    Ext.encode(App.GridPanel1.getRowsValues());
  5. #5
    Daniil,

    I have not used DirectMethods yet in any code. The store holding the data is associated with a Chart.

    I create the chart, named "CrtsChart", in code behind along with the Store, named "ChartStore".

    In the markup I have the export button that when selected should start the process of export the data the an excel file.

    Would you be able to give me a little more code to get started?
  6. #6
    Hope this helps.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store s = this.Chart1.GetStore();
                s.DataSource = new object[]
                {
                    new 
                    {
                        x = 0,
                        y = 0  
                    },
                    new 
                    {
                        x = 50,
                        y = 50  
                    },
                    new 
                    {
                        x = 100,
                        y = 100   
                    }
                };
                s.DataBind();
            }
        }
    
        [DirectMethod]
        public void Export(string data)
        {
            X.Msg.Alert("Exported", data).Show();
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Chart 
                ID="Chart1" 
                runat="server" 
                Width="400" 
                Height="400">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="x" />
                                    <ext:ModelField Name="y" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <Axes>
                    <ext:NumericAxis Title="X" Fields="x" Position="Bottom" />
                    <ext:NumericAxis Title="Y" Fields="y" Position="Left" />
                </Axes>
                <Series>
                    <ext:LineSeries Titles="Chart" XField="x" YField="y" />
                </Series>
            </ext:Chart>
    
            <ext:Button
                runat="server" 
                Text="Export" 
                Handler="App.direct.Export(Ext.encode(App.Chart1.getStore().getRecordsValues()));" />
        </form>
    </body>
    </html>

Similar Threads

  1. [CLOSED] Export Chart as Image
    By jchau in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Feb 28, 2014, 5:14 AM
  2. [CLOSED] How to Export SVG chart from code behind
    By feanor91 in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 27, 2013, 6:20 AM
  3. [CLOSED] export chart to SVG
    By CarpFisher in forum 2.x Legacy Premium Help
    Replies: 30
    Last Post: Jun 07, 2012, 7:49 AM
  4. Replies: 1
    Last Post: Apr 19, 2010, 2:44 PM
  5. Export data + IE6
    By _Belial in forum 1.x Help
    Replies: 0
    Last Post: Apr 01, 2009, 10:06 AM

Posting Permissions