首頁 > web前端 > js教程 > 主體

最佳化效能:為資料透視表選擇最佳資料來源

WBOY
發布: 2024-09-04 14:31:32
原創
844 人瀏覽過

Optimize Performance: Choose the Best Data Source for Pivot Table

TL;DR: Syncfusion Pivot Table 連接到多個資料來源,使其成為資料分析的多功能工具。選擇正確的資料來源對於效能至關重要。本指南探討了不同的選項,並提供了選擇最佳選項的提示。

Syncfusion Pivot Table 是一個強大的資料分析和視覺化工具。其突出的功能之一是能夠連接到各種資料來源,使其成為企業和開發人員的多功能選擇。為資料透視表選擇正確的資料來源對於確保最佳效能和可用性至關重要。

讓我們探索可以連接到 Syncfusion 資料透視表的不同資料來源、它們的優點以及如何選擇最適合您需求的資料來源。

了解 Syncfusion 資料透視表

在深入研究資料來源之前,有必要了解 Syncfusion 資料透視表是什麼及其運作方式。 Syncfusion 資料透視表是適用於 ASP.NET MVC、ASP.NET Core、TypeScript、JavaScript、Angular、React、Vue 和 Blazor 平台的元件。它允許您建立用於資料分析的互動式表格,提供資料過濾、排序、分組和聚合等功能。

選擇資料透視表資料來源時要考慮的因素

讓我們來看看為資料透視表選擇資料來源時需要考慮的一些重要因素:

數據量和複雜性

資料的大小會影響效能。大型資料集可能需要更強大的資料庫或最佳化的儲存解決方案。例如,JSON 或 CSV 檔案可能足以滿足中小型資料集。對於較大的資料集,請考慮使用關聯式和 NoSQL 資料庫或 OLAP 系統。 OLAP系統為複雜資料分析和多維資料提供了必要的能力。對於更直接的分析,JSON 或 CSV 檔案是實用的。

性能要求

考慮您的應用程式的效能要求。與基於文件的資料來源相比,資料庫通常為大規模資料操作提供更好的效能。但是,JSON 和 CSV 檔案可能足以進行快速、直接的分析。

易於集成

評估資料來源與 Syncfusion 資料透視表整合的難易度。關聯式資料庫和 JSON/XML 檔案通常具有完善的整合方法,而某些 NoSQL 資料庫和 RESTful API 可能需要額外的配置。

即時數據訪問

如果您的應用程式需要即時資料訪問,請使用具有即時功能的 RESTful API 或資料庫。 Excel 和 CSV 等基於文件的資料來源是靜態的,需要手動更新。

安全性和合規性

確保您選擇的資料來源符合您組織的安全和隱私要求。資料庫通常提供強大的安全功能,而基於文件的資料來源可能需要額外的措施來保護敏感資訊。

為資料透視表選擇資料來源的最佳實踐

讓我們來看看為資料透視表選擇資料來源的一些最佳實踐:

評估您的用例

了解您應用程式的特定需求並選擇符合這些需求的資料來源。考慮資料類型、所需操作和使用者期望。考慮用於需要高可用性和可擴展性的 Web 應用程式的 NoSQL 資料庫。對於使用結構化資料的傳統業務應用程式來說,像 SQL Server 這樣的關聯式資料庫是一個不錯的選擇。

測試效能和可擴展性

進行效能測試以確保所選資料來源能夠處理預期負載。另外,請考慮未來的可擴展性需求並選擇可以隨您的應用程式一起擴展的解決方案。

確保數據品質

數據品質對於準確分析至關重要。選擇允許您保持高資料品質標準的資料來源,包括驗證和錯誤檢查。

數據整合規劃

制定清晰的計劃,將資料來源與 Syncfusion 資料透視表整合。考慮使用中間件或 ETL(提取、轉換、載入)工具來簡化整合過程。 JSON 和 CSV 資料方便快速設定且易於使用。關聯式資料庫和 OLAP 系統需要更多的設定和維護,但提供了更強大的功能。

Syncfusion 資料透視表如何與不同的資料來源搭配使用?

靈活且強大的資料綁定功能促進了 Syncfusion 資料透視表處理各種資料來源的能力。它支援多種資料來源,包括:

  • JSON 資料:JSON 輕量級且易於使用,非常適合中小型資料集。
  • OLAP(線上分析處理):適合大型資料集和複雜的資料分析。
  • 關聯式資料庫:MySQL、SQL Server 和 PostgreSQL 等 SQL 資料庫提供強大的資料儲存和查詢功能。
  • NoSQL 資料庫: NoSQL 資料庫(如 MongoDB)為非結構化資料提供靈活的模式設計。
  • Web 服務:Web 服務,例如 RESTful API 和 OData 服務,有助於即時資料整合和動態更新。
  • CSV 檔案:對於較小的資料集和快速設定來說很簡單。

JSON資料

JSON(JavaScript 物件表示法)是一種輕量級資料交換格式。 Syncfusion 資料透視表可以輕鬆使用 JSON 數據,這對於通常從 API 中以 JSON 格式獲取資料的 Web 應用程式特別有用。

優點

  • 易於使用:JSON 易於讀取、編寫和解析,使其成為 Web 應用程式的熱門選擇。
  • 靈活性:JSON 可以處理各種資料結構,包括巢狀物件和陣列。

  • 輕量級:JSON 很緊湊,減少了透過網路傳輸的資料。

注意事項

  • 效能:處理 JSON 中的大型資料集可能效率低且緩慢。

  • 可擴充性有限:JSON 不適合大型或複雜的資料集。

何時使用

  • 中小型資料集。
  • 優先考慮易用性和快速設定的應用程式。

  • 原型設計與測試。

這是將 JSON 資料與我們的資料透視表整合的程式碼範例。

透過本地綁定JSON資料

var localData = [
    { Product: 'Bike', Country: 'USA', Sales: 100 },
    { Product: 'Car', Country: 'Canada', Sales: 200 }
];

var pivotTableObj = new ej.pivotview.PivotView({
    dataSourceSettings: {
        dataSource: localData,
        rows: [{ name: 'Product' }],
        columns: [{ name: 'Country' }],
        values: [{ name: 'Sales' }],
        filters: []
    }
});
pivotTableObj.appendTo('#PivotTable');
登入後複製

透過遠端(外部)連結綁定 JSON 資料

var pivotGridObj = new ej.pivotview.PivotView({
    dataSourceSettings: {
        url: 'https://cdn.syncfusion.com/data/sales-analysis.json',
        expandAll: false,
        rows: [
            { name: 'EnerType', caption: 'Energy Type' }
        ],
        columns: [
            { name: 'EneSource', caption: 'Energy Source' }
        ],
        values: [
            { name: 'PowUnits', caption: 'Units (GWh)' },
            { name: 'ProCost', caption: 'Cost (MM)' }
        ],
        filters: []
    }
});
pivotGridObj.appendTo('#PivotTable');
登入後複製

CSV 檔案

逗號分隔值 (CSV) 檔案是匯出和匯入資料的標準格式。 Syncfusion Pivot Table 可以解析 CSV 檔案並將其用作資料來源,從而可以輕鬆分析電子表格或其他表格資料來源中的資料。

優點

  • 簡單性:易於建立、閱讀和操作。
  • 可移植性:CSV 檔案廣泛支援且易於共用。
  • 快速設定:非常適合快速設定和小型資料集。

注意事項

  • 效能:不適合大型資料集或複雜查詢。
  • 功能有限:缺乏進階功能和資料類型。

何時使用

  • 用於快速分析或原型設計的小資料集。
  • 資料移轉或匯入/匯出場景。
  • 簡單的應用程序,資料操作需求最少。

這是將 CSV 資料與資料透視表整合的程式碼範例。

透過本地綁定CSV資料

var csvdata =
  'Region,Country,Item Type,Sales Channel,Total Revenue,Total Cost,Total Profit\r\nMiddle East and North Africa,Libya,Cosmetics,Offline,3692591.20,2224085.18,1468506.02\r\nNorth America,Canada,Vegetables,Online,464953.08,274426.74,190526.34\r\nMiddle East and North Africa,Libya,Baby Food,Offline,387259.76,241840.14,145419.62\r\nAsia,Japan,Cereal,Offline,683335.40,389039.42,294295.98';
var pivotObj = new ej.pivotview.PivotView({
  dataSourceSettings: {
    dataSource: getCSVData(),
    type: 'CSV',
    expandAll: false,
    formatSettings: [
      { name: 'Total Cost', format: 'C0' },
      { name: 'Total Revenue', format: 'C0' },
      { name: 'Total Profit', format: 'C0' },
    ],
    drilledMembers: [{ name: 'Item Type', items: ['Baby Food'] }],
    rows: [{ name: 'Country' }, { name: 'Region' }],
    columns: [{ name: 'Sales Channel' }, { name: 'Item Type' }],
    values: [
      { name: 'Total Profit' },
      { name: 'Total Cost' },
      { name: 'Total Revenue' },
    ],
    filters: [],
  },
  height: 290,
  width: '100%',
});
pivotObj.appendTo('#PivotTable');
function getCSVData() {
  var dataSource = [];
  var jsonObject = csvdata.split(/\r?\n|\r/);
  for (var i = 0; i < jsonObject.length; i++) {
    dataSource.push(jsonObject[i].split(','));
  }
  return dataSource;
}
登入後複製

透過遠端(外部)連結綁定 CSV 資料

var pivotObj = new ej.pivotview.PivotView({
    dataSourceSettings: {
        url: 'https://bi.syncfusion.com/productservice/api/sales',
        type: 'CSV',
        expandAll: false,
        enableSorting: true,
        formatSettings: [{ name: 'Total Cost', format: 'C0' }, { name: 'Total Revenue', format: 'C0' }, { name: 'Total Profit', format: 'C0' }],
        drilledMembers: [{ name: 'Item Type', items: ['Baby Food'] }],
        rows: [
            { name: 'Region' },
            { name: 'Country' }
        ],
        columns: [
            { name: 'Item Type' },
            { name: 'Sales Channel' }
        ],
        values: [
            { name: 'Total Cost' },
            { name: 'Total Revenue' },
            { name: 'Total Profit' }
        ],
        filters: []
    },
    height: 300,
    width: '100%'
});
pivotObj.appendTo('#PivotTable');
登入後複製

OLAP(線上分析處理)數據

OLAP 多維資料集允許進行複雜的資料分析,通常用於商業智慧應用程式。 Syncfusion Pivot Table 支援 OLAP 資料來源,透過豐富的分層資料結構實現多維資料分析。由於預先聚合的數據,OLAP 資料來源通常可以提供更快的查詢回應。

優點

  • 效能:OLAP 專為快速查詢和資料分析而設計,即使對於大型資料集也是如此。
  • 複雜分析:支援複雜計算、聚合、多維度資料分析。
  • 可擴充性:OLAP系統可以輕鬆處理大量資料集。

注意事項

  • 複雜性:設定和維護 OLAP 系統可能很複雜並且需要專業知識。
  • 成本:OLAP 解決方案的實施和維護成本可能很高。

何時使用

  • 具有複雜分析要求的大型資料集。
  • 商業智慧和資料倉儲應用程式。
  • 需要高效能和可擴展性的場景。

這是將 OLAP 資料與資料透視表整合的程式碼範例。

var pivotTableObj = new ej.pivotview.PivotView({
    dataSourceSettings: {
            catalog: 'Adventure Works DW 2008 SE',
            cube: 'Adventure Works',
            providerType: 'SSAS',
            enableSorting: true,
            url: 'https://bi.syncfusion.com/olap/msmdpump.dll',
            localeIdentifier: 1033,
            rows: [{ name: '[Customer].[Customer Geography]'],
            columns: [{ name: '[Product].[Product Categories]'},
                { name: '[Measures]'}],
            values: [{ name: '[Measures].[Customer Count]'},
                { name: '[Measures].[Internet Sales Amount]']
    }
});
pivotTableObj.appendTo('#PivotTable');
登入後複製

Relational databases

Relational databases are one of the most common data sources for our Pivot Table. They store data in tables, making it easy to retrieve and manipulate data using SQL queries. Popular relational databases include MySQL, PostgreSQL, SQL Server, and Oracle.

Advantages

  • Structured data: Data is organized in a tabular format, ideal for Pivot Tables.
  • Scalability: Suitable for handling large volumes of data.
  • ACID compliance: Ensures data integrity and consistency.

Considerations

  • Complexity: Requires knowledge of SQL for data retrieval.
  • Performance: This may require optimization for large datasets.

When to use

  • Medium to large datasets.
  • Apps requiring robust data storage and complex queries.
  • Scenarios where data integrity and relationships are essential.

NoSQL databases

NoSQL databases such as MongoDB offer a flexible schema and are designed to handle unstructured data, making them a good choice for certain types of data analysis.

Advantages

  • Flexibility: Schema-less design allows for easy modification of data structures.
  • Scalability: Excellent for handling large-scale, distributed data.

Considerations

  • Query complexity: Can be more complex to query than relational databases.
  • Consistency: May sacrifice consistency for availability and partition tolerance (CAP theorem).
  • Connectivity: We may require specific connectors or APIs for integration.

Web Services or remote data

Data can be fetched from remote servers using web services or APIs. Syncfusion Pivot Table can connect to remote data sources via RESTful services, making it ideal for apps that analyze data from various endpoints. It involves retrieving data from remote servers or databases.

Advantages

  • Real-time data: Enables real-time data integration and dynamic updates.
  • Scalability: Can handle large and distributed datasets.
  • Flexibility: Easily integrate with various services and APIs.

Considerations

  • Complexity: Requires developing and maintaining RESTful APIs.
  • Latency: Network latency can impact performance.

When to use

  • Apps needing real-time data updates.
  • Integrating data from multiple sources or external APIs.
  • Scenarios requiring high flexibility and scalability.

Here’s a code example for connecting an API service to our Pivot Table.

var data = new ej.data.DataManager({
    url: 'https://bi.syncfusion.com/northwindservice/api/orders',
    adaptor: new ej.data.WebApiAdaptor(),
    crossDomain: true,
  });
  data.defaultQuery = new ej.data.Query().take(8);

  var pivotTableObj = new ej.pivotview.PivotView({
    dataSourceSettings: {
      dataSource: data,
      expandAll: true,
      filters: [],
      columns: [{ name: 'ProductName' }],
      rows: [{ name: 'ShipCountry' }, { name: 'ShipCity' }],
      formatSettings: [{ name: 'UnitPrice', format: 'C0' }],
      values: [{ name: 'Quantity' }, { name: 'UnitPrice' }],
    },
    height: 350,
    width: '100%',
    gridSettings: { columnWidth: 120 },
  });
  pivotTableObj.appendTo('#PivotTable');
登入後複製

References

For more details, refer to the following references:

  • Connecting to PostgreSQL in Pivot Table
  • Connecting to Microsoft SQL Server in Pivot Table
  • Connecting to Oracle in Pivot Table
  • Connecting to Elasticsearch in Pivot Table
  • Connecting to Snowflake in Pivot Table
  • Server-Side Pivot Engine in Pivot Table

Conclusion

Thanks for reading! In this blog, we’ve explored the various options, benefits, and best practices for choosing the right data source for the Syncfusion Pivot Table, ensuring optimal performance and usability.

If you’re already a Syncfusion user, the latest version of Essential Studio is available on the License and Downloads page. We offer our new users a 30-day free trial to explore all our components’ features and capabilities.

If you need further assistance, contact us via our support forum, support portal, or feedback portal. We’re always here to help you!

Related blogs

  • Easily Group Data into Ranges in Web Applications Using Pivot Table
  • Optimize Memory Management in JavaScript Pivot Table: Best Practices and Tips
  • Easily Perform CRUD Actions in Blazor Pivot Table with SQL Database & Entity Framework
  • Efficient Report Management: Save and Load Reports in Vue Pivot Table with SQL Server and Node.js Express Server

以上是最佳化效能:為資料透視表選擇最佳資料來源的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!