Ad
Scatter Plot Remains Grey
I am using React Victory to plot different datasets and functions in a project. However I am unable to color scatter plot points.
I have tried with the following piece of code:
import React, { Component } from "react";
import { VictoryChart, VictoryScatter, VictoryTheme } from 'victory';
import './input_component.css'
class InputComponent extends Component {
constructor(props) {
super(props);
this.state = { }
}
render() {
return (
<div className = "input_layer">
<VictoryChart
theme={VictoryTheme.material}
domain={{ x: [-1, 1], y: [-1, 1] }}>
<VictoryScatter
size={5}
data={[{x:-0.7, y:1, fill: "blue"}, {x:0.5, y:-0.2, fill: "red"}]}
/>
</VictoryChart>
</div>
);
}
}
export default InputComponent;
From this I get a scatter plot chart, however all data points are grey instead of the color I specify as the "fill" argument.
Looking at the documentation for the data prop here, it would seem like I should be able to specify a color through the "fill" argument.
If anyone has suggestions to what I am doing wrong, I would be glad to hear them.
Ad
Answer
I know it's late but it will help someone. Using style prop in victoryScatter will solve your problem.
<VictoryScatter
size={5}
data={[{x:-0.7, y:1, fill: "blue"}, {x:0.5, y:-0.2, fill: "red"}]}
style={{
data: {
fill: ({ datum }) => datum.fill,
}
}}
/>
You can add any style property you want in the style props.
Ad
source: stackoverflow.com
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?
Ad