0

ここでは、(サンプルアプリケーションで提供されているのと同じコードを使用して)データソースを割り当ててグラフを作成しようとしていますが、違いはWPFWindowsFormsHostで行っていることだけです。何らかの理由でデータソースが適切に割り当てられておらず、作成されているシリーズ(「シリーズ1」)を確認できません。有線のことは、Windowsフォームアプリケーションでは機能しますが、WPFアプリケーションでは機能しないということです。

私は何かが足りないのですか、誰かが私を助けることができますか?

ありがとう

<Window x:Class="SEDC.MDM.WinUI.WindowsFormsHostWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" 
  xmlns:CHR="clr- namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.Dat  aVisualization"
  Title="HostingWfInWpf" Height="230" Width="338">
  <Grid x:Name="grid1">
  </Grid>
  </Window>


private void drawChartDataBinding()
{
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
string fileNameString = @"C:\Users\Shaik\MSChart\WinSamples\WinSamples\data\chartdata.mdb";

// initialize a connection string 
string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

// define the database query 
string mySelectQuery = "SELECT * FROM REPS;";

// create a database connection object using the connection string 
OleDbConnection myConnection = new OleDbConnection(myConnectionString);

// create a database command on the connection using query 
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
Chart Chart1 = new Chart();
// set chart data source
Chart1.DataSource = myCommand;

// set series members names for the X and Y values 
Chart1.Series"Series 1".XValueMember = "Name";
Chart1.Series"Series 1".YValueMembers = "Sales";

// data bind to the selected data source
Chart1.DataBind();

myCommand.Dispose();
myConnection.Close();
host.Child = Chart1;
this.grid1.Children.Add(host); 
} 

シャイク

4

1 に答える 1

0

次の 2 つの変更により、コードを修正できます。

1 - 代わりに

Chart1.Series"Series 1".XValueMember = "Name"; 
Chart1.Series"Series 1".YValueMembers = "Sales";

書きます

Chart1.Series["Series 1"].XValueMember = "Name"; 
Chart1.Series["Series 1"].YValueMembers = "Sales";

2 - 上記のコードの前に、次の行を挿入します。

Chart1.ChartAreas.Add("Default");
Chart1.Series.Add(new Series("Series 1"));
于 2010-06-05T17:46:08.103 に答える