Search code examples
c#wpfgraphdynamic-data-display

Set range for values for graph axes using DynamicDataDisplay


I am creating a application where in I want to plot a graph with DateTime as X-axis and numbers from 0-100 as Y-axis.

I have used the following code

     <d3:ChartPlotter.HorizontalAxis>
        <d3:HorizontalDateTimeAxis Name="dateAxis"/>
     </d3:ChartPlotter.HorizontalAxis>
     <d3:ChartPlotter.VerticalAxis>
        <d3:VerticalIntegerAxis Name="countAxis"  />   
     </d3:ChartPlotter.VerticalAxis>


     <d3:Header FontFamily="Times New Roman" Foreground="SteelBlue"  Content="Radiation Monitoring System"/>
     <d3:VerticalAxis FontFamily="Times New Roman" Foreground="SteelBlue" Content="Radiation Number" HorizontalAlignment="Center"  VerticalAlignment="Top" Height="346" Width="179" />
     <d3:HorizontalAxis FontFamily="Times New Roman" Foreground="SteelBlue" Content="Real time" HorizontalAlignment="Center" />

  </d3:ChartPlotter>

How am I suppose to set the Y-axisvalues between 0 - 100 ?

Also I need to set the content of Y-axis as we see in the normal graphs.(rotated 270 degrees)


Solution

  • I'm not sure of your second requirement(rotation), but to limit your y axis values, you can use the ViewPort.Domain. Domain sets the bounds for your plotter. Example :

    var axis = (DateTimeAxis)productPlot.MainHorizontalAxis;
    double yMin = 0;
    double yMax = 100;       
    Rect domainRect = new Rect(xMin, yMin, xMax - xMin, yMax - yMin);
    //xMin and xMax are left to your discretion based on your DateTimeAxis
    
    plotter.ViewPort.Domain = domainRect;
    

    If you could explain your second requirement more, I will try my best to update my answer with what is required.