1

I am using extjs 4.2.2 Chart. My requirement is to display a line chart also want to display the values in the node. In some of the posts I saw that can be done using Series label. Somehow it is not displaying the values in the node or the datapoints. Following is the chart code.

items : [ {
    xtype : 'chart',
    // renderTo : Ext.getBody(),
    width : 1600,
    animate : true,
    height : 400,
    shadow : true,
    // theme: 'Category2',
    store : 'SWeatherPoint',
    axes : [ {
        title : 'Temperature',
        type : 'Numeric',
        position : 'left',
        fields : [ 'temperature' ],
        minimum : 0,
        maximum : 100,
        minorTickSteps : 1,
        // grid: true
        grid : {
            odd : {
                opacity : 1,
                fill : '#ddd',
                stroke : '#bbb',
                'stroke-width' : 0.5
            }
        }
    }, {
        title : 'Day of the Month',
        type : 'Time',
        position : 'bottom',
        fields : [ 'date' ],
        dateFormat : 'M d',
        constrain : true,
        fromDate : new Date('1/1/07'),
        toDate : new Date('1/30/07'),
        grid : true
    } ],
    series : [ {
        type : 'line',
        xField : 'date',
        yField : 'temperature',
        highlight : {
            size : 7,
            radius : 7
        },
        axis : 'left',
        smooth : true,
        fill : true,
        label : {
//              display : 'under', // or 'rotate'
             field : 'temperature',
            renderer : function(label, storeItem, item, i, display,         animate, index) {
                console.log(this);
                console.log(item.get('temperature')+''+item+'' + i+''+display+ ''+index);
                return String(item.get('temperature'));
            }


        },
        tips : {
            trackMouse : true,
            width : 200,
            height : 28,
            renderer : function(storeItem, item) {
                this.setTitle(storeItem.get('temperature') + ': '
                        + storeItem.get('date') + ' views');
            }
        },
        style : {
            fill : '#18428E',
            stroke : '#18428E',
            'stroke-width' : 3,
            'stroke-dasharray' : 10
        // You need to add this!
        },
        markerConfig : {
            type : 'circle',
            size : 4,
            radius : 4,
            'stroke-width' : 0,
            fill : '#18428E',
            stroke : '#18428E'
        }
    } ]

It will be helpful if someone could point the issue.

Thanks, Amit

Dutta
  • 663
  • 2
  • 11
  • 30

1 Answers1

2

Looks like you are just missing items, and change setTitle to setText.

tips: {
        trackMouse: true,
        layout: 'fit',
        items: [{
            xtype: 'label'
        }],
        renderer: function (storeItem, item) {
            this.down('label').setText(storeItem.get('temperature') + Ext.util.Format.date(storeItem.get('date'), 'm/d/Y') + ' views');
        }
    },

Edit: Adding example of HighCharts:

Here's an example where I took yahoo.com historical stock prices and made a stock chart out of them.

var chart = Ext.create('Chart.ux.Highcharts', {
itemId: 'stockChartH',
axes: [{
type: 'Numeric',
position: 'left',
fields: ['Close'],

label: {
    renderer: Ext.util.Format.numberRenderer('0,0')
},
title: 'Price',
grid: true,
minimum: 0
}, {
type: 'Category',
position: 'bottom',
fields: ['Date'],
title: 'Date',
label: {
    renderer: function (value, label, storeItem, item, i, display, animate, index) {
        return Ext.util.Format.date(value, 'm/d');
    }
}

}],

series:[{
    dataIndex: 'Close',
    name: 'Stock Price',
    tips: {
        trackMouse: true,
        layout: 'fit',
        items: [{
            xtype: 'label'
        }],
        renderer: function (storeItem, item) {
            this.down('label').setText(Ext.util.Format.date(storeItem.get('Date'),      'm/d/Y') + ': ' + storeItem.get('Close') + ' Closing Price');
        }
    }
}],
xField: 'Date',
store: 'yahoo.yahooHistorical_s',
chartConfig: {
    chart: {
        type: 'spline',

    },
      title: {
        text: ' '
    },

    xAxis: {
        type: "date",
        labels: {
            formatter: function (value, label, storeItem, item, i, display, animate, index) {
                return Ext.util.Format.date(value, 'm/d');
                        }                    
                    },
        plotLines: [{
            color: '#FF0000',
            width: 5,
            title: 'test',
            value: 'mar',

        }]
    },
            yAxis: {
        title: {
            text: 'Price'
        }
    }
}
});
JesseRules
  • 723
  • 5
  • 17
  • tips works fine for me. I want something which will display the "temperature" constantly in the graph not only at the mouse hover to the datapoints. In the series component i added a lebel for the purpose. but it is not displaying the temperature value at the datapoint. – Dutta Jun 12 '14 at 21:14
  • Ahhh. Got it. Got to run but this looks promising: http://stackoverflow.com/questions/20216570/i-want-to-show-node-value-in-extjs-4-line-chart – JesseRules Jun 12 '14 at 21:32
  • Thanks Jesse.. I already visited the thread... I tried the way they have mentioned, but no luck – Dutta Jun 13 '14 at 17:06
  • Yeah, I screwed around with it for a while too and couldn't get it to work. You cant put in straight HTML either from what I can tell so you can't over-ride it. I couldn't find any examples online of anyone doing this either. I have had success with HighCharts but Ext.Net has a cool vertical line on the chart that shows you the data: http://examples.ext.net/#/Chart/Line/Multiple_Axes/ – JesseRules Jun 16 '14 at 13:54
  • Well, spoke with Ext guys,this is a bug in 4.2.2 and the fix will arrive in 4.3 version. We have to override to this in this version. You are right High chart is the way to go. Can we mix highchart with Extjs? Have you done that by chance? – Dutta Jun 16 '14 at 15:55
  • I edited my answer to show an example of one high chart I did to use yahoo's historical stock quote feed to make a stock chart. It was actually pretty easy to do. – JesseRules Jun 16 '14 at 17:37
  • Jesse thanks for the highchart code. By chance do you have the code with the package structure. I mean the complete folder of the ext+highchart project. I am kind of struggling to get a standalone example for the same. – Dutta Jun 18 '14 at 19:58