Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Axis with different interval between two major divisions

Hi all, I have question about the axis interval. The example is I have a series of data with index of 1, 2, 3, .., 100. I would like to map 40 to 1, 70 to 2, 90 to 3 and 100 to 4. Therefore, in the line graph, the major divisions of X axis are only 1, 2, 3 and 4. If I use Mode: Interval 0, 1, I am able to get the labels of the major divisions of 1, 2, 3 and 4. However, the distance between two consecutive ticks are the same. How can I make the distance between two consecutive labels to reflect the number of samples between them. For example, the length between 0 to 1 should be longer than 1 to 2 because 0 to 1 has 40 samples while 1 to 2 has only 30 samples. Thank you.

0 Kudos
Message 1 of 3
(4,140 Views)

Hi benedict1986,

 

I don't know if it is possible to have a varying number of minor divisions between each pair of major divisions on a graph.  I did find this article that talks about customizing axis ranges:

http://zone.ni.com/reference/en-XX/help/372636F-01/mstudiowebhelp/html/editingaxisrangenetgraphswinf...

 

I did find some sample code that may let you create your own tick marks by inheriting the x-axis and drawing your own tick marks:

  private void button4_Click(object sender, EventArgs e) 
        { 
            int numberOfSamples = 9; 
            double[] actualData = new double[]{ 0, 1, 2, 3, 10, 11, 17, 18, 19}; 
  
            //Normal XAxis 
            waveformGraph1.PlotY(actualData); 
  
            //Customized XAxis 
            double[] indexData = new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8}; 
            xAxis2.MajorDivisions.GridVisible = false; 
            xAxis2.MajorDivisions.TickVisible = false; 
            xAxis2.MajorDivisions.LabelVisible = false; 
  
            for (int i = 0; i < numberOfSamples; i++ ) 
            { 
                // Basically use custom divisions to display any text you want!!!!! 
               xAxis2.CustomDivisions.Add(new AxisCustomDivision(indexData[i], actualData[i].ToString())); 
            } 
  
            waveformGraph2.PlotY(actualData); 
        } 

Let me know if that helps!

 

--G-IV

 

0 Kudos
Message 2 of 3
(4,120 Views)

Based on your other question, I assume you are using a WPF graph control. Since you have a fixed set of divisions you want to display, while maintaining the existing spacing of the data, I would suggest setting both MajorDivisions and MinorDivisions to null, and using custom divisions for the specific values you want to display.


Here is a self-contained example for the values and labels you indicated:


    <ni:Graph x:Name="graph">
        <ni:Graph.Resources>
            <niPrimitives:MatchedValueConverter x:Key="CustomDivisionConverter">
                <niPrimitives:MatchPair Value="40" Result="1" />
                <niPrimitives:MatchPair Value="70" Result="2" />
                <niPrimitives:MatchPair Value="90" Result="3" />
                <niPrimitives:MatchPair Value="100" Result="4" />
            </niPrimitives:MatchedValueConverter>

            <ni:TemplateValuePresenter x:Key="CustomDivisionPresenter">
                <DataTemplate>
                    <TextBlock Text="{Binding Mode=OneWay, Converter={StaticResource CustomDivisionConverter}}" />
                </DataTemplate>
            </ni:TemplateValuePresenter>
        </ni:Graph.Resources>

        <ni:Graph.Axes>
            <ni:AxisDouble x:Name="xAxis"
                           Orientation="Horizontal"
                           MajorDivisions="{x:Null}"
                           MinorDivisions="{x:Null}">
                <ni:AxisDouble.CustomDivisions>
                    <ni:CustomDivision Value="40" LabelPresenter="{StaticResource CustomDivisionPresenter}" />
                    <ni:CustomDivision Value="70" LabelPresenter="{StaticResource CustomDivisionPresenter}" />
                    <ni:CustomDivision Value="90" LabelPresenter="{StaticResource CustomDivisionPresenter}" />
                    <ni:CustomDivision Value="100" LabelPresenter="{StaticResource CustomDivisionPresenter}" />
                </ni:AxisDouble.CustomDivisions>
            </ni:AxisDouble>
        </ni:Graph.Axes>
    </ni:Graph>

~ Paul H
0 Kudos
Message 3 of 3
(4,113 Views)