简体   繁体   中英

Call a visiblox chart that created with c# code in wpf

Is there a way to call a Visiblox Chart that created with C# code in WPF?

Let's say that i have created a chart like :

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;
}

And when I import some date from a CSV file, I want to add more data from another CSV file. Is there a way to call this created Chart with each name, or something?

Thanks in advance.

<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>

Then in your codebehind 'myChart' will be available and you can do all the setup and configuration of the chart in your MainWindow methods:

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

etc. 'myChart' will be scoped to your MainWindow class, so you can make whatever helper methods you need to setup you chart.

However, doing everything in code behind isn't the WPF way, the WPF way would be to setup most or all of it in XAML. You can see the examples on their website in how to control the charts through XAML. http://www.visiblox.com/examples/LineChart

If I understand what your asking correctly, you wouldn't reference the Chart object by it's Name property - that is really only if you have it added on the UI. Instead, you would store the object somewhere (global variable, collection of Chart objects, etc) and then call the objects directly from that store.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM