MindFusion.Wpf Pack Programmer's Guide
Axes

This topic is only relevant for charts that use the Cartesian coordinate system.

The XAxesYAxes, X2Axes and Y2Axes are used for setting the properties of the axes. Each chart can have as many axes of each type as needed. Create an object of type Axis, set the desired properties and add it to the respective AxesCollection cited above.

In 3D surface charts the properties for the Z-axis are set with ZAxisSettings. The labels at each axis depend on LabelType.

If the LabelType is LabelType.CustomText there are two options for placing custom labels:

Custom labels are placed either at data points or at the intervals of the axis - see the CustomLabelPosition property. The Title property sets the title of the axis.

Custom labels are specified with the Labels property. Of course, you can use data binding - specify the name of the data bound property with LabelPath.

The sample code demonstrates how to set custom labels using a list as well using a data bound property:

C#  Copy Code

barChart1.DataSource = salesStatistics;
Axis xAxis = new Axis();
xAxis.LabelPath = "Products";
xAxis.LabelType = LabelType.CustomText;
barChart1.XAxes.Add(xAxis);

Axis yAxis = new Axis();
yAxis.LabelType = LabelType.CustomText;
yAxis.Labels = new string[] { "2008", "2009", "2010"};
barChart1.YAxes.Add(yAxis);

VB.NET  Copy Code

barChart1.DataSource = salesStatistics
barChart1.XLabelPath = "Products"
barChart1.YLabels = New String() {"2008", "2009", "2010"}

The axis can be customized by the MinValue, MaxValue and Interval. They set the exact start and end numbers as well the size thus the count of the intervals between them.

You can set the count of the intervals at the axis explicitly with the IntervalCount property. In this case, the Interval property will not be considered and the length of the interval will be calculated based on Axis.MinValue, Axis.MaxValue and Axis.IntervalCount.

The sample code below shows how to set an axis that shows the divisions from 0 to 1000, divided at intervals of 100:

C#  Copy Code

Axis xAxis = new Axis();
xAxis.MinValue = 0;
xAxis.MaxValue = 1000;
xAxis.Interval = 100;
barChart1.XAxes.Add(xAxis);

VB.NET  Copy Code

barChart1.XAxisSettings.MinValue = 0
barChart1.XAxisSettings.MaxValue = 1000
barChart1.XAxisSettings.Interval = 100

If you want to use DateTime data in your chart, please refer to the DateTime Values topic - there are detailed instructions how to set the chart axis when data is DateTime values.

Second Y-axis

If you want to show the second Y-axis, all you should create an Axis object and add it to the Y2Axes property. Set the scale with Axis.MinValue, Axis.MaxValue and Axis.Interval. Alternatively you can set the value of the Y2Data or Y2DataPath properties in an axes chart - in this case an Y2 axis will be calculated and drawn automatically.

Second X-axis

If you want to show the second X-axis, you need to create an Axis object and it to the X2Axes property just like you do with the other axes. If you set the value of the X2Data or X2DataPath properties in an axes chart the axes will be drawn automatically based on your data.

XAML

When you want to write the code for your axes in design time using XAML the right way to do it is to initialize the whole AxesCollection rather than adding one more axis to it. This way the collection is reset and all axes that might have been added as default will be cleared.

XAML (correct)  Copy Code

 <chart:BarChart Name="barChart1" Margin="0,0,26,28">
            <chart:BarChart.XAxes>
                <chart:AxesCollection>
                    <chart:Axis MinValue="0" MaxValue="100" Interval="10" LabelType="AutoScale" LabelRotationAngle="40.0"></chart:Axis>
                </chart:AxesCollection>
        </chart:BarChart.XAxes>
            </chart:BarChart>
      

If you directly add the Axis, the collection shall not be reset, a possible default axis will be present and you migh end up having two axes instead of one:

XAML (wrong)  Copy Code

<chart:BarChart Name="barChart1" Margin="0,0,26,28">
            <chart:BarChart.XAxes>              
                    <chart:Axis MinValue="0" MaxValue="100" Interval="10" LabelType="AutoScale" LabelRotationAngle="40.0"></chart:Axis>
           </chart:BarChart.XAxes>
</