2011-12-22 122 views
0

有沒有辦法調用使用WPF中的C#代碼創建的Visiblox Chart調用在wpf中使用c#代碼創建的visiblox圖表

比方說,我創建了像圖:

private Chart CreateNewChart(int num_chart, string chartName) 
{ 
    Chart newChart = new Chart(); 
    newChart.Name = "Chart_"+num_chart; 
    newChart.Title = chartName; 
    newChart.Width = 600; 
    newChart.Height = 120; 
    newChart.Background = Brushes.Transparent; 
    newChart.HorizontalAlignment = HorizontalAlignment.Left; 
    newChart.VerticalAlignment = VerticalAlignment.Top; 
    newChart.Margin = new Thickness(0, (num_chart * 110), 0, 0); 
    BehaviourManager behaviour = new BehaviourManager(); 
    behaviour.AllowMultipleEnabled = true; 
    TrackballBehaviour track = new TrackballBehaviour(); 
    ZoomBehaviour zoom = new ZoomBehaviour(); 
    behaviour.Behaviours.Add(track); 
    behaviour.Behaviours.Add(zoom); 
    newChart.Behaviour = behaviour; 
    return newChart; 
} 

而當我輸入一些日期從CSV文件,我想從另一個CSV文件中添加更多的數據。有沒有辦法用這個名字創建Chart

在此先感謝。

回答

1
<Window x:Class="ThingNamespace.MainWindow" 
    xmlns:ctest="clr-namespace:ThingNamespace" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:charts="clr-namespace:Visiblox.Charts;assembly=Visiblox.Charts" 
    Title="MainWindow" Height="400" Width="600" x:Name="TheWindow"> 

    <charts:Chart x:Name="myChart" /> 
</window> 

然後在你的代碼隱藏「myChart」將可用,你可以做圖表的所有安裝和配置在主窗口的方法:

public MainWindow() 
{ 
    InitializeComponent(); 
    myChart.Title = chartTitle; 
    myChart.Width = 600; 
    myChart.Height = 120; 
    ... 
} 

等「myChart」將範圍限定爲你的MainWindow類,所以你可以做任何你需要設置你圖表的輔助方法。

但是,在代碼背後做所有事情並不是WPF的方式,WPF的方式是在XAML中設置大部分或全部。您可以在他們的網站上看到如何通過XAML控制圖表的示例。 http://www.visiblox.com/examples/LineChart

+0

我的練習是創建一個程序,每當我按下一個按鈕時,我都會動態創建一個名爲import的拖動按鈕的visiblox聊天,另一個命名爲more ...我現在可以動態地使用c#生成儘可能多的我想線圖,並把它們放在一個網格與他們的按鈕..當我按導入一切都很好,但是當我想從另一個文件中添加更多的線條在圖表中,我想知道如何從一個特定的按鈕調用用一個名稱與te圖表相同的名稱來再次實例化圖表並添加更多行......謝謝 – Anaisthitos 2011-12-22 14:20:25

0

如果我明白你的要求是正確的,你不會通過它的Name屬性來引用Chart對象 - 這實際上只有當你在UI中添加它時纔會這樣做。相反,您可以將對象存儲在某處(全局變量,對象集合等),然後直接從該存儲中調用對象。

+0

不,我的意思是:用csv文件的數據與代碼創建一個圖表,並把它放在一個網格中。然後用一個按鈕解析來自另一個csv文件的一些數據,並將它們動態地導入到以前的圖表中......如果它是在xaml中,那麼綁定之類的東西很容易,但現在它全部是用c#代碼從頭開始創建的。 – Anaisthitos 2011-12-22 14:15:59

相關問題