chart.primaryYAxis = {labelFormat: 'n0'};
if(jQuery('#slctCategory').find('option:selected').attr('isCurrency')==1){
chart.primaryYAxis = {labelFormat: 'c'};
}
|
// add your additional code here <div class="col-md-3"> LabelFormat </div>
<div class="col-md-3 aligntop"> <select name="selectIndex" autocomplete="off" id="type"> <option value="{value}%">%</option> <option value="n0">n0</option> <option value="c">c</option> </select> </div> <script type="text/javascript"> $(function () { $("#container").ejChart( { // add your additional code here
}); $('#type').change(function () { var chart = $("#container").ejChart("instance"); chart.model.primaryYAxis.labelFormat= $('#type')[0].value; chart.redraw(); }); }); </script> |
chart.primaryYAxis.labelFormat='n0';
if(jQuery('#slctCategory').find('option:selected').attr('isCurrency')==1){
chart.primaryYAxis.labelFormat='c';
}
The only problem is a now get this error in the browser console and the crosshair tooltip stops working (this error increments every pixel the mouse moves over the chart):
constants.js:93 Uncaught TypeError: e.toFixed is not a function
at Function.e.processFraction (constants.js:93)
at Function.e.intNumberFormatter (constants.js:93)
at t.format (constants.js:93)
at t.formatPointValue (constants.js:93)
at t.parseTemplate (constants.js:93)
at t.getTooltipText (constants.js:93)
at t.renderGroupedTooltip (constants.js:93)
at t.tooltip (constants.js:93)
at t.mouseMoveHandler (constants.js:93)
at e.notify (constants.js:93)
The code for the chart is:var chart = new ej.charts.Chart({
width: '1020',
height: '500',
useGroupingSeparator: true,
zoomSettings:
{
enableMouseWheelZooming: true,
enablePinchZooming: true,
enableSelectionZooming: true
},
primaryXAxis: {
majorGridLines: { width: 0 },
valueType: 'DateTime',
crosshairTooltip: { enable: true },
labelFormat: 'MM-dd'
},
primaryYAxis:
{
crosshairTooltip: { enable: true }
},
annotations: [{ // watermark for chart
content: 'XXXXX Report™',
x: '13%',
y: '84%',
coordinateUnits: 'Pixel',
verticalAlignment: 'Top'
},
],
tooltip: { enable: true, shared: true, format: '${series.name} - ${point.y}' },
crosshair: { enable: true },
});
|
var chart = new ej.charts.Chart({
width: '1020', height: '500', useGroupingSeparator: true, zoomSettings: { enableMouseWheelZooming: true, enablePinchZooming: true, enableSelectionZooming: true }, primaryXAxis: { majorGridLines: { width: 0 }, valueType: 'DateTime', crosshairTooltip: { enable: true }, labelFormat: 'MM-dd' }, primaryYAxis: { crosshairTooltip: { enable: true } }, annotations: [{ // watermark for chart content: '<div id="chart_cloud">XXXXX Report™</div>', x: '13%', y: '84%', coordinateUnits: 'Pixel', verticalAlignment: 'Top' }, ], series: [ { type: 'Line', dataSource: [ { x: new Date(2005, 0, 1), y: 21 }, { x: new Date(2006, 0, 1), y: 24 }, { x: new Date(2007, 0, 1), y: 36 }, { x: new Date(2008, 0, 1), y: 38 }, { x: new Date(2009, 0, 1), y: 54 }, { x: new Date(2010, 0, 1), y: 57 }, { x: new Date(2011, 0, 1), y: 70 } ], xName: 'x', width: 2, marker: { visible: true, width: 10, height: 10 }, yName: 'y', name: 'Germany', }, { type: 'Line', dataSource: [ { x: new Date(2005, 0, 1), y: 28 }, { x: new Date(2006, 0, 1), y: 44 }, { x: new Date(2007, 0, 1), y: 48 }, { x: new Date(2008, 0, 1), y: 50 }, { x: new Date(2009, 0, 1), y: 66 }, { x: new Date(2010, 0, 1), y: 78 }, { x: new Date(2011, 0, 1), y: 84 } ], xName: 'x', width: 2, marker: { visible: true, width: 10, height: 10 }, yName: 'y', name: 'England', } ], tooltip: { enable: true, shared: true, format: '${series.name} - ${point.y}' }, crosshair: { enable: true }, }); chart.appendTo('#line-container'); |