Short.io のデータをDevExpress Data Grid にデータバインドする。

加藤龍彦
加藤龍彦
デジタルマーケティング
CData API Driver for ADO.NET をDevExpress のWindows Forms およびWeb コントロールと組み合わせて使い、チャートに Short.io のデータ を取り込みます。



CData API Driver for ADO.NET は、サードパーティ製コントロールと組み合わせて使える標準的なADO.NET データアクセスコンポーネントを備えています。通常のADO.NET データバインドの手順に沿って進めるだけで、UI コントロールからリアルタイムデータへの双方向アクセスを実現できます。この記事では、CData のコンポーネントを使って DevExpress UI コントロール(Windows Forms およびWeb コントロール) にデータバインドする方法を紹介します。今回は、リアルタイムのデータを可視化するチャートにデータバインドしていきます。

API キー認証の設定

Short.io は API キー認証を使用します。API キーを取得するには、以下のステップで進めます:

  1. Short.io アカウントにログインします
  2. Settings > Integrations & API > API に移動します
  3. Create API Key をクリックして API キーをコピーします

API キーを取得したら、接続を確立できます:

  • AuthScheme:APIKey に設定します。
  • APIKey:Settings > Integrations & API > API から取得した Short.io の API キーに設定します。

接続文字列の例:

Profile=C:\profiles\ShortIo.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_api_key';

利用可能なテーブル

Short.io プロファイルでは、以下のテーブルにアクセスできます:

  • Domains - 認証済みアカウントに関連付けられた Short.io ドメイン
  • Links - ドメインの短縮リンク
  • LinkExpand - ドメインとパスから短縮リンクを展開
  • LinksByOriginalUrl - 指定した元の宛先 URL に一致する複数の短縮リンクを取得
  • Folders - 特定のドメイン内のリンクフォルダー
  • LinkPermissions - ドメイン内の特定のリンクの権限レコード
  • CountryTargeting - 特定の短縮リンクの国別リダイレクトターゲティングルール
  • RegionTargeting - 特定の短縮リンクの地域別リダイレクトターゲティングルール
  • Regions - 指定した国コードに対する利用可能な地域/州の一覧
  • DomainStatistics - Short.io ドメインのクリック数とトラフィックの集計統計
  • LinkStatistics - 特定の Short.io リンクのクリック数とトラフィックの集計統計

Windows Forms コントロール

下のコードでは、Short.io でDevExpress のチャートに追加する方法を説明します。APIDataAdapter はチャートコントロールのSeries プロパティにバインドします。コントロールのDiagram プロパティはx 軸とy 軸をカラム名として定義します。

using (APIConnection connection = new APIConnection(
"Profile=C:\profiles\ShortIo.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_api_key';")) {
  APIDataAdapter dataAdapter = new APIDataAdapter(
  "SELECT ,  FROM Domains WHERE  = ''", connection);

  DataTable table = new DataTable();
  dataAdapter.Fill(table);
  DevExpress.XtraCharts.Series series = new DevExpress.XtraCharts.Series();
  chartControl1.Series.Add(series);
  DataTable table = new DataTable();
  series.ValueDataMembers.AddRange(new string[] { "" });
  series.ArgumentScaleType = DevExpress.XtraCharts.ScaleType.Qualitative;
  series.ArgumentDataMember = "";
  series.ValueScaleType = DevExpress.XtraCharts.ScaleType.Numerical;
  chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
  ((DevExpress.XtraCharts.SideBySideBarSeriesView)series.View).ColorEach = true;
}
The complete code example and the resulting chart.

Web コントロール

下のコードではShort.io でDevExpress Web を操作するための設定方法を説明します。APIDataAdapter はチャートのSeries プロパティにバインドします。Diagram プロパティはx 軸とy 軸をカラム名として定義します。

using DevExpress.XtraCharts;

using (APIConnection connection = new APIConnection(
"Profile=C:\profiles\ShortIo.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_api_key';"))
{
  APIDataAdapter APIDataAdapter1 = new APIDataAdapter("SELECT ,  FROM Domains WHERE  = ''", connection);
  DataTable table = new DataTable();
  APIDataAdapter1.Fill(table);
  DevExpress.XtraCharts.Series series = new Series("Series1", ViewType.Bar);
  WebChartControl1.Series.Add(series);
  DataTable table = new DataTable();
  series.ValueDataMembers.AddRange(new string[] { "" });
  series.ArgumentScaleType = ScaleType.Qualitative;
  series.ArgumentDataMember = "";
  series.ValueScaleType = ScaleType.Numerical;
  ((DevExpress.XtraCharts.SideBySideBarSeriesView)series.View).ColorEach = true;
}
An ASP.NET application created with the ADO.NET Provider and the DevExpress Web Forms control.(Salesforce is shown.)

はじめる準備はできましたか?

API Driver で Short.io のライブデータに接続

Short.io に接続