bizchart折线图案例
https://bizcharts.alibaba-inc.com/product/BizCharts4/demo/399
image.png

告警线数据

  • 告警设置 alert: true, count: Number
  • 不是告警的清除 count: null

image.png
image.png

bizchart3.8.0需要设置2个刻度

  1. const scale = {
  2. date: {
  3. alias: "日期",
  4. type: "time",
  5. tickCount: 10,
  6. mask: 'HH:mm',
  7. },
  8. count: {
  9. alias: "状态",
  10. type: 'cat',
  11. values: ['离线', '在线'],
  12. range: [0, 1]
  13. },
  14. };
  15. const alertScale = {
  16. ...scale,
  17. count: {
  18. alias: "状态",
  19. tickCount: 2,
  20. max: 1,
  21. min: 0,
  22. range: [0, 1]
  23. },
  24. }

bizchart4.x

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {
  4. Chart,
  5. Line,
  6. Legend,
  7. Axis,
  8. Tooltip,
  9. Point,
  10. View,
  11. } from "bizcharts";
  12. const scale = {
  13. date: {
  14. alias: "日期",
  15. type: "time",
  16. tickCount: 10,
  17. mask: 'HH:mm',
  18. },
  19. count: {
  20. alias: "状态",
  21. type: 'cat',
  22. values: ['离线', '在线'],
  23. range: [0, 1]
  24. },
  25. };
  26. LineChart.propTypes = {
  27. dataSource: PropTypes.array.isRequired,
  28. height: PropTypes.number,
  29. padding: PropTypes.array,
  30. };
  31. LineChart.defaultProps = {
  32. height: 360,
  33. padding: [24, 16, 24, 24],
  34. }
  35. function LineChart({dataSource, height, padding}) {
  36. const alertLine = dataSource.map((item) => {
  37. return item.alert ? item : {...item, count: null};
  38. });
  39. return (
  40. <Chart
  41. autoFit
  42. height={height}
  43. padding={padding}
  44. scale={{
  45. count: {
  46. sync: true,
  47. },
  48. }}
  49. className='mb32'
  50. >
  51. <Tooltip />
  52. <View data={dataSource} scale={scale}>
  53. <Axis name="count" />
  54. <Line
  55. position="date*count"
  56. color="#9AD681"
  57. size={2}
  58. tooltip={[
  59. "count*alert",
  60. (count, alert) => {
  61. return {
  62. name: "状态",
  63. color: alert ? '#f00' : '#9AD681',
  64. value: count ? '在线' : '离线',
  65. };
  66. },
  67. ]}
  68. />
  69. <Point
  70. position="date*count"
  71. shape='circle'
  72. color={[
  73. "date*alert",
  74. (count, alert) => {
  75. return alert ? '#f00' : "#9AD681";
  76. },
  77. ]}
  78. tooltip={false}
  79. />
  80. </View>
  81. <View data={alertLine} scale={scale}>
  82. <Line
  83. position="date*count"
  84. color="#f00"
  85. size={2}
  86. tooltip={false}
  87. />
  88. </View>
  89. <Legend visible={false}/>
  90. </Chart>
  91. );
  92. }
  93. export default LineChart;

滑块Bug

折线图,默认显示滑块,如何解决?

  • bizChart4.x 用 Line 代替

https://bizcharts.net/product/BizCharts4/category/62/page/81#slidable
image.png
在 Chart里面设置:

image.png

image.png