DataChart
DataChart takes an array of objects in data
and provides various visualization capabilities on that data. It attempts to default as much as it possibly can to make it easy to get started and then customize later. What follows is some guidance on how to get started and then delve into what DataChart can do.
series
To begin with, give your DataChart some data and set the series
property to indicate which properties in the data objects should be used.
Note that the X and Y axis are defaulted and the dates are automatically formatted based on the granularity given.
chart
Next, we can customize the kind of chart we are looking at.
axis and guide
Next, we can customize the axis and add guide lines.
string
"a user friendly label for screen readers"
string
"start"
"center"
"end"
"stretch"
"baseline"
boolean
true
false
string
"date"
object
{ x: boolean | string | { granularity: "...", property: "date" }, y: boolean | string | { granularity: "...", "property": "amount" } ] }
"coarse"
"medium"
"fine"
string
"align"
object
{ x: [0, 100], y: [0, 100], }
string
"property"
object
{ property: "...", color: "...", dash: boolean, opacity: "...", pattern: "...", point: "...", round: boolean, thickness: "...", type: "..." }
"string"
array["property1", "property2"]
array[{ property: "...", color: "..." }]
{ color: "string" | { property: "...", transform: function }, thickness: "...", x: "string", y: "string" }
"string"
{ dark: "string", light: "string" }
"weak"
"medium"
"strong"
number
boolean
"squares"
"circles"
"stripesHorizontal"
"stripesVertical"
"stripesDiagonalDown"
"stripesDiagonalUp"
"circle"
"diamond"
"square"
"star"
"triangle"
"triangleDown"
"hair"
"xsmall"
"small"
"medium"
"large"
"xlarge"
"none"
"string"
"bar"
"bars"
"line"
"area"
"areas"
"point"
array
[ { "date": "2020-05-28", "amount": 88, "percent": 20 }, { "date": "2020-05-27", "amount": 77, "percent": 15 } ]
boolean
true
false
string
"none"
"xsmall"
"small"
"medium"
"large"
"xlarge"
"string"
boolean
true
false
object
{ x: boolean | { granularity: "coarse" "medium" "fine" } y: boolean | { granularity: "coarse" "medium" "fine" } }
string
"none"
"xxsmall"
"xsmall"
"small"
"medium"
"large"
"xlarge"
object
{ vertical: "...", horizontal: "...", top: "...", bottom: "...", left: "...", right: "..." }
boolean
true
false
object
{ gap: "string" }
string
"none"
"xxsmall"
"xsmall"
"small"
"medium"
"large"
"xlarge"
"any CSS size"
object
{ vertical: "...", horizontal: "...", top: "...", bottom: "...", left: "...", right: "...", start: "...", end: "..." }
string
"loading..."
node
<Box>...</Box>
Describes which parts of the 'data' are of interest and how to handle them.
string
"property"
array[string]
["property1", "property2"]
object
'property' indicates which property of the 'data' objects this series refers to. 'label' indicates how to label the series in a legend or hover details. 'prefix' and 'suffix' are applied to the data values shown in an axis, legend, or details. 'render' allows custom rendering of the data value. 'render' is called with: (value, datum, property) => { return < />; }
{ label: "string", prefix: "$", property: "string", render: (value, datam, dataIndex) => element, suffix: "%" }
array[object]
[ { label: "string", prefix: "$", property: "string", render: (value, datam, dataIndex) => element, suffix: "%" }, ]
At its core, the DataChart component is a regular <div> element. Thus, both DOM and React properties, methods, and events are accessible. To read up on all of the possible DOM attributes and types available for div elements, check out this MDN Web Documents page. To learn more about DOM events and methods, you can read more on the MDN Web Events documentation page.
Also, feel free to read about the types of React events available, or see how DOM attributes change in React. Working in tandem with Styled Components, you also have access to the as property.