D3BarChart.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. define( ["https://d3js.org/d3.v3.min.js"], function( d3 ) {
  2. "use strict";
  3. function D3BarChart()
  4. {
  5. };
  6. D3BarChart.prototype.draw = function( oControlHost )
  7. {
  8. var o = oControlHost.configuration;
  9. var iWidth = ( o && o.Width ) ? o.Width : 500;
  10. var iHeight = ( o && o.Height ) ? o.Height : 16;
  11. var sBackgroundColor = ( o && o["Background color"] ) ? o["Background color"] : "#C8F08F";
  12. var fnScale = d3.scale.linear()
  13. .domain( [0, d3.max( this.m_aData )] )
  14. .range( [0, iWidth] );
  15. d3.select( oControlHost.container )
  16. .selectAll( "div" )
  17. .data( this.m_aData )
  18. .enter().append( "div" )
  19. .style( "width", function( d ) { return fnScale( d ) + "px"; } )
  20. .style( "background-color", sBackgroundColor )
  21. .style( "border", "1px solid gray" )
  22. .style( "margin", "4px 0px 4px 0px")
  23. .style( "height", iHeight + "px" )
  24. .style( "line-height", iHeight + "px" )
  25. .text( function( d ) { return d; } );
  26. };
  27. D3BarChart.prototype.setData = function( oControlHost, oDataStore )
  28. {
  29. this.m_oDataStore = oDataStore;
  30. this.m_aData = [];
  31. var iRowCount = oDataStore.rowCount;
  32. for ( var iRow = 0; iRow < iRowCount; iRow++ )
  33. {
  34. this.m_aData.push( oDataStore.getCellValue( iRow, 1 ) );
  35. }
  36. };
  37. return D3BarChart;
  38. });