Gas Gauge Demo

From ZedGraphWiki

Jump to: navigation, search

Image:gasgauge.png

// Call this method from the Form_Load method, passing your ZedGraphControl
public void CreateChart( ZedGraphControl zgc )
{
    GraphPane myPane = zgc.GraphPane;
    
    // Define the title
    myPane.Title.Text = "Gas Gauge Demo";
    
    // Fill the pane with gray
    myPane.Fill = new Fill( Color.LightGray, Color.White, 45.0f );
    // Fill the chart rect with blue
    myPane.Chart.Fill = new Fill( Color.White, Color.SkyBlue, 45.0f );
    
    // Don't show any axes for the gas gauge
    myPane.XAxis.IsVisible = false;
    myPane.Y2Axis.IsVisible = false;
    myPane.YAxis.IsVisible = false;
    
    //Define needles; can add more than one
    GasGaugeNeedle gg1 = new GasGaugeNeedle( "Cereal", 30.0f, Color.Black );
    GasGaugeNeedle gg2 = new GasGaugeNeedle( "Milk", 80.0f, Color.DarkGreen );
    myPane.CurveList.Add( gg1 );
    myPane.CurveList.Add( gg2 );
    
    //Define all regions
    GasGaugeRegion ggr1 = new GasGaugeRegion( "Red", 0.0f, 33.0f, Color.Red );
    GasGaugeRegion ggr2 = new GasGaugeRegion( "Yellow", 33.0f, 66.0f, Color.Yellow );
    GasGaugeRegion ggr3 = new GasGaugeRegion( "Green", 66.0f, 100.0f, Color.Green );
    
    // Add the curves
    myPane.CurveList.Add( ggr1 );
    myPane.CurveList.Add( ggr2 );
    myPane.CurveList.Add( ggr3 );
    
    zgc.AxisChange();
}


Go back to Sample Graphs

Personal tools