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

How to add title in Axis by "alias"?? #3

Closed
chuyinweilai opened this issue Nov 23, 2017 · 3 comments
Closed

How to add title in Axis by "alias"?? #3

chuyinweilai opened this issue Nov 23, 2017 · 3 comments

Comments

@chuyinweilai
Copy link

I follow this deemo: https://github.com/alibaba/BizCharts/blob/master/demo/component/area/basic.js and add “alias” in cols:
image
this is all of my code:


import React,  { Component } from 'react';
import { Chart, Geom, Axis, Tooltip, Coord, Label, Legend, Shape } from 'bizcharts';
import DataSet from '@antv/data-set';

const ds = new DataSet();
export default class Series extends Component {
	constructor(){
		super();
		this.state={
			data: [],
			cols: {},
		}
	}
	componentWillMount(){
		this.setState({
			data: [
				{ month: 'Jan', Tokyo: 7.0, London: 3.9 },
				{ month: 'Feb', Tokyo: 6.9, London: 4.2 },
				{ month: 'Mar', Tokyo: 9.5, London: 5.7 },
				{ month: 'Apr', Tokyo: 14.5, London: 8.5 },
				{ month: 'May', Tokyo: 18.4, London: 11.9 },
				{ month: 'Jun', Tokyo: 21.5, London: 15.2 },
				{ month: 'Jul', Tokyo: 25.2, London: 17.0 },
				{ month: 'Aug', Tokyo: 26.5, London: 16.6 },
				{ month: 'Sep', Tokyo: 23.3, London: 14.2 },
				{ month: 'Oct', Tokyo: 18.3, London: 10.3 },
				{ month: 'Nov', Tokyo: 13.9, London: 6.6 },
				{ month: 'Dec', Tokyo: 9.6, London: 4.8 }
			],
			cols: {
				temperature:{ alias: '销售量' },
				month: {
					alias: '横坐标',
					range:[0,1]
				}
			},
		})
	}

        render() {
		const dv = ds.createView().source(this.state.data);
		dv.transform({
			type: 'fold',
			fields: [ 'Tokyo', 'London', 'baseLine' ], // 展开字段集
			key: 'city', // key字段
			value: 'temperature', // value字段
			alias: '纵坐标',
		});
		// forceFit设置图表的宽度是否自适应
                return (
				<Chart height={400} data={dv} scale={this.state.cols} forceFit>
					<Axis name="month"/>
					<Axis name="temperature" label={{formatter: val => `${val}°C`}}/>
					<Tooltip crosshairs={{type : "y"}}/>
					<Legend/>
					<Geom type="line" position="month*temperature" size={2} color={'city'} />
				</Chart>
    );
  }

But, it's no use:
image

@chuyinweilai
Copy link
Author

There is another problem about
The Y-axis can't show the border like this:
image
This is the same code.

@weepy3641
Copy link
Member

Axis' title is hidden default ,alias is just give a field data an alias name ,do not mean axis title show。

you should add title property in Axis component. title={{}}

like this:
that means the month Axis 's title should be showed.

thanks for your issue;
we will adjust axis title property's value and doc in the next bizcharts@3.0.3 version.
like this:
or

@chuyinweilai
Copy link
Author

@weepy3641 I can't see your example……
image
But I see what you means and understand the API of Axis.title:

<Axis name="temperature" label={{formatter: val => `${val}°C`}} 
	 title={{
		 autoRotate: true, // 是否需要自动旋转,默认为 true
		 offset: 40, // 设置标题 title 距离坐标轴线的距离
		 textStyle: {
			 fontSize: '12',
			 textAlign: 'center',
			 fill: '#999',
			 fontWeight: 'bold',
		 },
		 position: 'center', // 标题的位置,**新增**
	 }} 
 />

image

Thanks for your help!

weepy3641 pushed a commit that referenced this issue Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants