ChartDirector 7.1 (.NET Edition)

Path Specification


Many ChartDirector APIs expect a path for loading a file. Examples include BaseChart.setBgImage and the CDML <*img*> tag.

ChartDirector supports two types of paths - file system path and resource path. If the path starts with "@/", it is a resource path, otherwise it is a file system path.

File System Path

The file system path is the path used to access files in the file system.

If a relative path is used, it will be relative to the "current working directory" determined by the operating system. This may not be the same as the directory that contains the executing code.

You may use BaseChart.setSearchPath to specify other directories to search if a relative path is used.

For web applications, note that a file system path is not the same as a URL path. For example, a leading "/" refers to the root of the file system, not the root of the web document directory. This allows files outside of the web document directory to be used.

Depending on the web server, the "current working directory" may not be the same as the current URL directory. If you would like to load a file relative to the current URL directory, you may use BaseChart.setSearchPath to specify searching the current URL directory for files. For example:

c.setSearchPath(Server.MapPath("."))

What is a Resource

Many applications require images. For example, the application icon is an image. Pushbuttons or toolbars may have images or icons on them. To avoid having to distribute many images files with the application, many application frameworks have facilities to allow these contents to be embedded into the executable. These embedded contents are referred to as resources.

In the .NET framework, there are several types of resources. They are described as follows.

Embedded Resource

Embedded resource, also called manifest resource, is the original .NET resource type and is the suggested resource type to be used with ChartDirector. To create an embedded resource, add the image file to the Visual Studio project, and in the property page for the image file, set the "Build Action" to "Embedded Resource".

Visual Studio will include the resource under the default namespace of the project. To use the resource in ChartDirector, the resource path should be in the format "@/default_namespace/folder/filename.ext" in C#, or "@/default_namespace/filename.ext" in VB. For example, if the default namespace is "test_project" and the image is in the "images" folder in the Visual Studio project and is called "my_wallpaper.png", the resource path in C# would be "@/test_project/images/my_wallpaper.png", and in VB it would be "@/test_project/my_wallpaper.png". Note that the C# compiler will include the folder in the resource path, while the VB compiler will not include the folder.

If you omit the namespace in the resource path, ChartDirector will assume it is the namespace of the entry point (or startup object) of the assembly.

ChartDirector assumes the resource is in the entry assembly, which is normally the EXE assembly for a desktop application. If the resource in another assembly, such as a separate DLL, you can specify the assembly with the syntax "@//assembly_name/default_namespace/folder/filename.ext" in C#, or "@//assembly_name/default_namespace/filename.ext" in VB. The leading "@//" tells ChartDirector it is a resource path that starts with an assembly name.to

XAML Compatible Resource

This type of resource can be used by XAML in WPF. It can be created by adding the image file to the Visual Studio project, and in the property page for the image file, set the “Build Action” to “Resource”.

Although ChartDirector can use XAML compatible resource, if you are not really using the same resource in XAML, we suggest you use "Embedded Resource" instead. It is because from our testing, if the XAML compatible resource is not actually used in XAML, Visual Studio may ignore newly added resources if "Build" is used to compile the project. You would need to use "Rebuild" to ensure all added resources are included in the compiled executable. This is inconvenient for code development.

To use XAML compatible resource in ChartDirector, the resource path should be in the format "@/folder/filename.ext". The "folder/filename.ext" refers to the path to the resource in the Visual Studio project.

ChartDirector assumes the resource is in the entry assembly, which is normally the EXE assembly for a desktop application. If the resource in another assembly, such as a separate DLL, you can specify the assembly with the syntax "@//assembly_name/folder/filename.ext". The leading "@//" tells ChartDirector it is a resource path that starts with an assembly name.

Other Resource Types

The .NET system has several other resource types, such as Form resources, or resources associated with ".res" or ".resx". They are not directly supported in ChartDirector. If you must use these resource types, you can use your own code to read the resource content to memory, then use Chart.setResource or BaseChart.setResource to assign an ID to the resource. The resource can then be referenced using "@/res_id", in which "res_id" is the resource ID.

Dynamic Resource

Normally, resources are static contents embedded into an application. ChartDirector also allows dynamic resources, which are contents generated or obtained at runtime. This allows dynamic contents to be used in APIs that expect a file or resource path. For example, you can use a dynamically generated image in CDML <*img*>, or retrieve an image (such as a map) from a database and use it as the background image of a chart, without having to save the image as a file first.

A dynamic resource can be a DrawArea object or an array of bytes containing the content. It can be assigned a resource ID using Chart.setResource, BaseChart.setResource, BaseChart.setResource2, DrawArea.setResource or DrawArea.setResource2. The resource can then be referenced as "@/res_id", in which "res_id" is the resource ID.