Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add legend samples #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 161 additions & 1 deletion examples/legend/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ import ReactDOM from 'react-dom';
import {
Legend,
PieChart,
ScatterplotChart
ScatterplotChart,
LineChart,
AreaChart,
BarChart
} from 'react-easy-chart';
import { escapeHTML } from '../util';
import Scrollspy from 'react-scrollspy';

const lineColors = [
{ color: '#3F4C55' },
{ color: '#E3A51A' },
{ color: '#F4E956' },
{ color: '#AAAC84' }
];

const pieData = [
{ key: 'Cats', value: 100 },
{ key: 'Dogs', value: 200 },
Expand Down Expand Up @@ -50,6 +60,7 @@ const scatterStyle = {
}
};


const bigData = [
{
type: 'One',
Expand Down Expand Up @@ -128,6 +139,35 @@ const bigData = [
}
];

const lineData = [
[
{ x: 'Mon', y: 20 },
{ x: 'Tue', y: 10 },
{ x: 'Wed', y: 33 },
{ x: 'Thu', y: 45 },
{ x: 'Fri', y: 15 }
], [
{ x: 'Mon', y: 10 },
{ x: 'Tue', y: 15 },
{ x: 'Wed', y: 13 },
{ x: 'Thu', y: 15 },
{ x: 'Fri', y: 10 }
],
[
{ x: 'Mon', y: 5 },
{ x: 'Tue', y: 40 },
{ x: 'Wed', y: 33 },
{ x: 'Thu', y: 12 },
{ x: 'Fri', y: 8 }
]
];

const barData = [
{ x: 'Cats', y: 20 },
{ x: 'Dogs', y: 10 },
{ x: 'Other', y: 25 }
];

export default class LegendContainer extends PureComponent {

constructor(props) {
Expand Down Expand Up @@ -179,6 +219,8 @@ export default class LegendContainer extends PureComponent {
<li><a href="#config">Config</a></li>
<li><a href="#styles">Styles</a></li>
<li><a href="#scatterplot">Scatterplot</a></li>
<li><a href="#linecharts">Line and area charts</a></li>
<li><a href="#barcharts">Bar charts</a></li>
</Scrollspy>
</nav>
</aside>
Expand Down Expand Up @@ -431,6 +473,124 @@ export default class LegendContainer extends PureComponent {
/>

</section>


<section id="linecharts">
<h2>Line and area charts</h2>
<p>Line and area charts example</p>
<pre>
{(() => {
const html = (`
<LineChart
data={lineData}
width={440}
height={270}
axes
xType={'text'}
/>

<AreaChart
data={lineData}
width={440}
height={270}
axes
xType={'text'}
/>

<Legend
data={[
{ key: 'Cats' },
{ key: 'Dogs' },
{ key: 'Other' }
]}
dataId={'key'}
horizontal
config={lineColors}
/>`);
return (
<code dangerouslySetInnerHTML={{ __html: escapeHTML(html) }} />
);
})()}
</pre>

<div style={{ float: 'left' }}>
<LineChart
data={lineData}
width={440}
height={270}
axes
xType={'text'}
/>
</div>
<div style={{ float: 'right' }}>
<AreaChart
data={lineData}
width={440}
height={270}
axes
xType={'text'}
/>
</div>
<div style={{ clear: 'both', textAlign: 'center' }}>
<Legend
data={[
{ key: 'Cats' },
{ key: 'Dogs' },
{ key: 'Other' }
]}
dataId={'key'}
horizontal
config={lineColors}
/>
</div>


</section>


<section id="barcharts">
<h2>Bar charts</h2>
<p>Bar charts example</p>
<pre>
{(() => {
const html = (`
<BarChart
data={barData}
width={480}
height={270}
axes
xType={'text'}
colorBars
/>

<Legend
data={barData}
dataId={'x'}
horizontal
/>`);
return (
<code dangerouslySetInnerHTML={{ __html: escapeHTML(html) }} />
);
})()}
</pre>


<BarChart
data={barData}
width={480}
height={270}
axes
xType={'text'}
colorBars
/>

<Legend
data={barData}
dataId={'x'}
horizontal
/>

</section>
</div>
</div>
);
Expand Down