[CLOSED] Bar Chart overlapping the Category Axis when there are only negative values

  1. #1

    [CLOSED] Bar Chart overlapping the Category Axis when there are only negative values

    Hi,

    I have a bar chart is plotted using positive & negative values, there are some scenario in which bar chart is plotted using negative values.
    The issue is, if the bar chart is build with the negative values, it is overlapping the Category Axis and if there is both negative & positive values chart is displaying correctly.

    Chart with Positive and Negative values:
    Click image for larger version. 

Name:	positive Bar.png 
Views:	31 
Size:	13.7 KB 
ID:	9941

    Chart with Negative values only.
    Click image for larger version. 

Name:	negative Bar.png 
Views:	37 
Size:	9.8 KB 
ID:	9951

    Here is my sample code:

    //Model

      public class ChartModel
            {
                public string Name { get; set; }
                public int Data1 { get; set; }
            }

    // Controller

    public StoreResult GenerateNegativData()
            {
                List<ChartModel> lst = new List<ChartModel>();
                ChartModel cm = new ChartModel();
    
                //*****To generate bar chart with Positive & negative values uncomment this******//
                //cm = new ChartModel();
                //cm.Name = "Country - 1";
                //cm.Data1 = 96498000;
                //lst.Add(cm);
    
                cm = new ChartModel();
                cm.Name = "Country - 2";
                cm.Data1 = -4289142;
                lst.Add(cm);
    
                cm = new ChartModel();
                cm.Name = "Country - 3";
                cm.Data1 = -4502571;
                lst.Add(cm);
    
                cm = new ChartModel();
                cm.Name = "Country - 4";
                cm.Data1 = -4929428;
                lst.Add(cm);
    
                return new StoreResult(lst);
            }
    
            public ActionResult NegativeBarChart()
            {
                return View();
            }
    // View

    
    
    @{
        ViewBag.Title = "Bar Chart";
        var X = Html.X();
    }
    
    @(Html.X().ResourceManager(ViewBag.ManagerConfig as MvcResourceManagerConfig))
    
    @{
        <h3>Bar Chart Sample</h3><br />
            
        
    
        @(X.Panel()
            .Title("Column Chart")
            .Layout(LayoutType.Fit)
            .Items(
                X.Chart()
                    .ID("Chart1")
                    .Width(800)
                    .Height(600)
                    .Shadow(true)
                    .StyleSpec("background:#fff;")
                    .Animate(true)
                    .Store(X.Store()
                        .Data(Model)
                        .Model(X.Model()
                            .Fields(
                                X.ModelField().Name("Name"),
                                X.ModelField().Name("Data1")
                            )
                        )
                        .Proxy(X.AjaxProxy()
                            .Url(Url.Action("GenerateNegativData"))
                            .Reader(X.JsonReader().Root("data"))
                        )
                    )
                    .Axes(
                        X.NumericAxis()
                            .Fields("Data1")
                            .Grid(true)
                            .Title("Revenue")
                            .Label(X.AxisLabel().Rotate(X.RotateAttribute().Degrees(0))
                                .Renderer(r => r.Handler = "return Ext.util.Format.number(value, '0,0');")
                            ),
                        X.CategoryAxis()
                            .Position(Position.Bottom)
                            .Fields("Name")
                            .Title("Scenario")
                             .Label(X.AxisLabel()
                                .Rotate(X.RotateAttribute().Degrees(315))
                            )
                           
                    )
                    .Series(X.ColumnSeries()
                        .Axis(Position.Left)
                        .Highlight(true)
                        .XField("Name")
                        .YField("Data1")
                        .Tips(X.ChartTip()
                            .TrackMouse(true)
                            .Width(140)
                            .Height(28)
                            .Renderer(r => r.Handler = "this.setTitle(storeItem.get('Name') + ': ' + storeItem.get('Data1'));")
                        )
                        .Label(X.SeriesLabel()
                            .Display(SeriesLabelDisplay.InsideEnd)
                            .Field(new [] { "Data1" })
                            .Orientation(Orientation.Horizontal)
                            .Color("#333")
                            .TextAnchor("middle")
                            .Renderer(r => r.Handler = "return Ext.util.Format.number(value, '0');")
                        )
                    )
            )
        )
    }
    Thanks
    Last edited by geoffrey.mcgill; Apr 18, 2014 at 5:23 PM. Reason: [CLOSED]
  2. #2
    Hi @PriceRightHTML5team,

    Yes, it is a problem. I can suggest the following solution.
    Ext.chart.axis.Axis.override({
        getRange: function() {
            var range = this.callParent(arguments);
    
            if (range.max < 0) {
                range.max = 1;
            }
    
            return range;
        }
    });
  3. #3
    Thanks Daniil..

    It is working fine.

Similar Threads

  1. Replies: 10
    Last Post: Sep 20, 2017, 2:31 AM
  2. [CLOSED] All the values are not getting plot on Numeric Axis in Chart
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 15, 2014, 3:54 PM
  3. [CLOSED] Bar Chart not displaying properly in case of Positive & negative values
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 03, 2014, 11:41 PM
  4. Replies: 2
    Last Post: Aug 13, 2012, 2:12 PM
  5. negative id values while exporting data
    By emon in forum 1.x Help
    Replies: 0
    Last Post: Mar 05, 2011, 6:12 AM

Posting Permissions