Guest User

Untitled

a guest
Jan 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. { headerName: 'Security Chart', field: 'SecurityChartData', width: 300, suppressMenu: true , cellRenderer: this.sparkLine }
  2.  
  3. sparkLine() {
  4. const dataAttr = "7, 5, 6, 6, 4 ".split('; ') ;
  5. const data = dataAttr[0].split(', ').map(Number);
  6. const options = {
  7. series: [{
  8. data,
  9. pointStart: 1
  10. }],
  11. chart: {
  12. type: dataAttr || 'area'
  13. }
  14. }
  15. return <SparkLine options={options} />
  16. }
  17.  
  18. import React, { Component } from 'react' ;
  19. import Highcharts from 'highcharts' ;
  20.  
  21.  
  22. const defaultOptions = {
  23. chart: {
  24. backgroundColor: null,
  25. borderWidth: 0,
  26. type: 'area',
  27. margin: [2, 0, 2, 0],
  28. width: 250,
  29. height: 40,
  30. style: {
  31. overflow: 'visible',
  32. align : 'center'
  33. },
  34.  
  35. // small optimalization, saves 1-2 ms each sparkline
  36. skipClone: true
  37. },
  38. title: {
  39. text: ''
  40. },
  41. credits: {
  42. enabled: false
  43. },
  44. xAxis: {
  45. labels: {
  46. enabled: false
  47. },
  48. title: {
  49. text: null
  50. },
  51. startOnTick: false,
  52. endOnTick: false,
  53. tickPositions: []
  54. },
  55. yAxis: {
  56. endOnTick: false,
  57. startOnTick: false,
  58. labels: {
  59. enabled: false
  60. },
  61. title: {
  62. text: null
  63. },
  64. tickPositions: [0]
  65. },
  66. legend: {
  67. enabled: false
  68. },
  69. tooltip: {
  70. backgroundColor: 'red',
  71. borderWidth: 1,
  72. hideDelay: 0,
  73. shared: true,
  74. padding: 8,
  75. borderColor: 'white',
  76. borderRadius: 3,
  77. positioner: function (w, h, point) {
  78. return { x: point.plotX - w / 2, y: point.plotY - h };
  79. }
  80. },
  81. plotOptions: {
  82. series: {
  83. animation: false,
  84. lineWidth: 1,
  85. shadow: false,
  86. states: {
  87. hover: {
  88. lineWidth: 1
  89. }
  90. },
  91. marker: {
  92. radius: 1,
  93. states: {
  94. hover: {
  95. radius: 2
  96. }
  97. }
  98. },
  99. fillOpacity: 0.25
  100. },
  101. column: {
  102. negativeColor: '#910000',
  103. borderColor: 'silver'
  104. }
  105. },
  106.  
  107. series: [{
  108. data: [1,2,3]
  109. }]
  110. };
  111.  
  112.  
  113. export default class SparkLine extends Component {
  114. constructor (props) {
  115. super(props)
  116. }
  117.  
  118. componentDidMount () {
  119. const options = Highcharts.merge(defaultOptions, this.props.options)
  120. this.chart = Highcharts.chart(this.container, options)
  121. }
  122.  
  123. componentWillUnmount () {
  124. this.chart.destroy()
  125. }
  126.  
  127. render () {
  128. return (
  129. <td
  130. ref={container => this.container = container}
  131. >
  132. </td>
  133. )
  134. }
  135. }
Add Comment
Please, Sign In to add comment